Script outputting 13 time no loops

This topic contains 3 replies, has 2 voices, and was last updated by  BrandonB 1 year, 2 months ago.

  • Author
    Posts
  • #54907

    BrandonB
    Participant

    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
    
    ______________________________________________________________________________________________________________
  • #54912

    Dan Potter
    Participant

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

  • #54913

    Dan Potter
    Participant
    
    $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
    
    
    }
    
    
  • #54914

    BrandonB
    Participant

    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.

You must be logged in to reply to this topic.