Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Help: if something equals a certain value, change value to 'x'

$
0
0

Using Select-Object in that way is sort of a nice shorthand for something like this:

$creds = Get-Credential

Get-ADComputer -Filter 'OperatingSystem -like "*2008*"' |
ForEach-Object {
    $computer = $_
    $snmpObject = Get-WmiObject -ComputerName $computer.Name -Credential $creds -Query "select *from win32_ServerFeature where name = 'snmp service' "

    if ($snmpObject -ne $null)
    {
        $isSnmpInstalled = $true
    }
    else
    {
        $isSnmpInstalled = $false
    }

    New-Object psobject -Property @{
        ComputerName = $computer.Name
        SNMPInstalled = $isSnmpInstalled
    }
} |
Export-Csv c:\servers\SNMPInstalled.csv -NoTypeInformation

They both get you PSObjects with the same properties, but I prefer how the pipeline looks when there’s not a big ForEach-Object loop stuck in the middle of it.


Viewing all articles
Browse latest Browse all 13067

Trending Articles