powershell get-aduser where manager -eq disabled -
im trying advertisement users user in manager field disabled
the below not work, ive tried multiple ways though cannot figure out
get-aduser -searchbase "xxx" -filter {enabled -eq $true} -properties * | {get-aduser -filter {distinguishedname -eq $_.manager -and enabled -eq $false}}
i don't have advertisement readily available has populated manager
attribute, script not tested. anyway, simple way create 2 collections get-aduser
. fill 1 disabled accounts , 1 enabled ones. loop through enabled accounts , check if manager found disableds.
to create things faster, store disabled accounts hash table group-object
, utilize hashtable's containskey()
method so,
$disabled = get-aduser -filter { enabled -ne $true } | group-object ` -ashashtable -asstring -property name $users = get-aduser -filter { enabled -eq $true } foreach($user in $users) { if( $disabled.containskey($user.manager) ) { # user's manager disabled business relationship } }
powershell
No comments:
Post a Comment