'Loop Through PSOBJECT To Compare Values to a String

Working on a script to get the status of Windows Defender components. Running into a challenge looping through the results from Get-MpComputerStatus as I'm wanting to write out which components are enabled and disabled.

The issue that I'm running into is I'm not able to get the specific value from the PSOBJECT and only get everything.

#Microsoft Defender Statuses
$DefenderStatus = Get-MpComputerStatus | select-object AMServiceEnabled, AntispywareEnabled, AntivirusEnabled, BehaviorMonitorEnabled, IoavProtectionEnabled, IsTamperProtected, IsVirtualMachine, NISEnabled, OnAccessProtectionEnabled, RealTimeProtectionEnabled

#Write results to a PSOBJECT
$result =  ([ordered]@{

            'Anti-Virus'=$DefenderStatus.AntivirusEnabled
            'Anti-Malware'=$DefenderStatus.AMServiceEnabled
            'Anti-Spyware'=$DefenderStatus.AntispywareEnabled
            'Behavior Monitor'=$DefenderStatus.BehaviorMonitorEnabled
            'Office-Anti-Virus'=$DefenderStatus.IoavProtectionEnabled
            'NIS'=$DefenderStatus.NISEnabled
            'Access Protection'=$DefenderStatus.OnAccessProtectionEnabled
            'R-T Protection'=$DefenderStatus.RealTimeProtectionEnabled

            })


foreach ($Status in $result)
{
   If ($Status.Values -eq $false)
   {
        Write-Host "$Status.Keys is Disabled"
        $Disabled = $Disabled + ", "  + $Status
   }
   Else
   {
        Write-Host "$Status.Keys is Enabled"
        $Enabled = $Enabled + ", "  + $Status

   }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source