Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

"foreach if..then " not working

$
0
0

after finding the correct syntax,

$employeeID=60001
if (Get-ADuser -LDAPfilter "(sAMAccountName=$employeeID)") {
  echo "found it!"
  Set-ADuser -Identity $employeeID -Add @{msExchExtensionAttribute16=3000}
}

now i'm trying to read a CSV file and loop over the above code for bulk modifications:

$userlist = Import-CSV C:\users3.csv
foreach ($person in $userlist) {
  echo $person.employeeID
  if (Get-ADuser -LDAPfilter "(sAMAccountName=$person.employeeID)") {
    echo "found it!"
  else
    echo "skipped!"
  }
}

the statement "echo $person.employeeID" works but the conditional doesn't seem to be doing anything. it won't do either of the echo command given.

how do you do a trace in powershell?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>