Hello!
I have a simple If/Else as part of a ForEach-Object loop…
$newStaff | ForEach-Object { Add-ADGroupMember "Staff 8e6" $newStaff.UserLogonName if ($_.CertifiedJob -eq '0' ) {Add-ADGroupMember "CLASSIFIED STAFF" $newStaff.UserLogonName} Else {Add-ADGroupMember "CERTIFICATED STAFF" $newStaff.UserLogonName} }
You can see, if $_.CertifiedJob -eq ‘0’ (0 is a STRING), I want the user to be added to a group.
If $_.CertifiedJob -eq ‘-1’ (again, a string), I want the user added to a different group.
I have tried, If ($_.Certifiedjob -like ‘0’), etc.
Right now, it is just adding the user to both AD groups in the statement.
I have been looking at the statement and the input and just cannot see why this is happening.
$newStaff = Import-CSV mycsv.csv, which it includes a column called ‘CertifiedJob’ which will always be a string, either ‘0’ or ‘-1’.
Thank you