Author Posts

October 4, 2016 at 1:16 pm

Can anyone please explain why the code keeps returning so many values? I'm trying to get either pass or fail not combinations of the two. I'm blatantly overlooking something here.

I'm trying to get values 2004, 1405, 1200

PS U:\> $strKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
$valueName = "testIsntInHere"
$objReg = [WMIClass]"root\default:StdRegProv"
$strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $valueName) | Select-Object -property ReturnValue 
$strResult = ""

switch ($strValue.ReturnValue) {
	0 {$strResult = "Enabled"
	   $status += "pass"}
	1 {$strResult = "Prompt"
	   $status += "fail"}
	3 {$strResult = "Disabled"
	   $status += "fail"}
	default {$strResult = "Unknown"}
}
$systemAttrs += ("Computer Authentication Check : " + $strResult)

Write-Output $status

fail
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass
pass

______________________________________________________________________________________________________________

October 4, 2016 at 1:50 pm

Every time you run it you're adding to status.

October 4, 2016 at 1:55 pm


$strKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3"
$valueName = "testIsntInHere"
$objReg = [WMIClass]"root\default:StdRegProv"
$strValue = $objReg.GetDWORDValue($HKEY_CURRENT_USER, $strKey, $valueName) | Select-Object -property ReturnValue 

switch ($strValue.ReturnValue) {

	0{$strResult = 'Enabled';$status = 'pass'}
	1{$strResult = 'Prompt';$status = 'fail'}
	3{$strResult = 'Disabled';$status = 'fail'}
	default{$strResult = "Unknown";$status='n/a'}
}


[pscustomobject]@{

value = $valueName
Results = $strResult
Status = $status


}

October 4, 2016 at 2:08 pm

Ah thank you kindly Mr. Potter! That explains why there's another script with a customPSObject then. I really appreciate the simple fix and answer.