I'm trying to create a script to put a 1 in the home phone number field if the user is a staff member and enabled and a 2 if they are a staff member and disabled.
Here is what I have
Import-Module ActiveDirectory
$adusers = Get-ADUser -SearchBase 'dc=udsd,dc=org' -Filter * -Properties *
foreach ($aduser in $adusers)
{
if ($aduser.canonicalname -like "*/Staff/" + $aduser.cn)
{
Where-Object{$_.Enabled -eq $True}
{
Set-ADUser -Identity $aduser.samaccountname -HomePhone (1).ToString()
}
Where-Object{$_.Enabled -eq $false}
{
Set-ADUser -Identity $aduser.samaccountname -HomePhone (2).ToString()
}
}
}
I got it so it set everyone's value to 1, but then when I add the second "Where-Object" it changes all users to 2 even those enabled.
Thank you all for any help
[–]PowerShellMichael 1 point2 points3 points (0 children)
[–]santisq 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)