Powershell - Filter results of varaible in pipeline -
i want limit results of $groups variable below return members of specific group. code retrieves groups computer belongs to. interested in members of ad group contains "sccm".
i tried line 5 doesn't work. correct method this? thanks.
$samaccountnames = (get-adcomputer computer).samaccountname $osinfo = get-wmiobject -class win32_operatingsystem -computername computer $servergroupmembershiplist = get-adprincipalgroupmembership $samaccountnames | sort samaccountname $groups = $servergroupmembershiplist.name #$groups = $servergroupmembershiplist.name | select {$servergroupmembershiplist.name -like "sccm"} write-host " " write-host "checking software updates compliance on" $computer.toupper() -foregroundcolor yellow -nonewline write-host $osinfo.caption $groups
rather using select-object
cmdlet, try using where-object
cmdlet filtering or ?
short. $_
variable current object being processed cmdlet.
$groups = $servergroupmembershiplist | where-object { $_.name -like "sccm" }
or
$groups = $servergroupmembershiplist | ? { $_.name -like "sccm" }
Comments
Post a Comment