powershell - Modify users based on Office location -
i can't work... ideas? basically, if user in chicago, claim user isn't , falls in else statement.
i want collect users in ad.
then want @ office location , based on located, set address....
 $users = get-adgroupmember "domain users" -recursive | select-object samaccountname  foreach ($user in $users) { if  (get-aduser -filter {samaccountname -eq '$user' -and office -eq "chicago"}) { set-aduser -streetaddress "66 chicago rd" -city "chicago" -postalcode "60618" -state "il" -country "us"  -replace @{ co="united states"; countrycode="804" } } else { (echo $user " not in chicago!")} } 
can try :
$users = get-adgroupmember "domain users" -recursive | select-object samaccountname  foreach ($user in $users) { if  (get-aduser -filter {samaccountname -eq $user.samaccountname -and office -eq "chicago"}) { set-aduser -streetaddress "66 chicago rd" -city "chicago" -postalcode "60618" -state "il" -country "us"  -replace @{ co="united states"; countrycode="804" } } else { (echo $user " not in chicago!")} } i replace
samaccountname -eq '$user'  by
samaccountname -eq $user.samaccountname 
Comments
Post a Comment