Import-Module activedirectory
$users = Get-ADUser -SearchBase "ou=ttemp,ou=tt,ou=staff,dc=hello,dc=com" -Filter *
foreach($i in $users){
$id = $i.SamAccountName
#$upn = $i.UserPrincipalName
#Write-Output $id,$upn
Set-ADUser -Identity $id -UserPrincipalName "[email protected]"
}
$users = Get-ADUser -SearchBase "ou=ttempou=tt,ou=staff,dc=hello,dc=com" -Filter * -Properties *| ? {$_.whencreated -gt '2022/04/05'}
foreach($i in $users){
$id = $i.SamAccountName
#$upn = $i.UserPrincipalName
#Write-Output $id,$upn
Set-ADUser -Identity $id -UserPrincipalName "[email protected]"
}
Get-ADUser -Filter {pwdLastSet -eq 0} -SearchBase "ou=ttemp,ou=tt,ou=staff,dc=hello,dc=com" | Set-ADUser -ChangePasswordAtLogon $false
Get-ADUser -Filter * -SearchBase "ou=Service_Accounts,ou=tt,ou=staff,dc=hello,dc=com" | Set-ADUser -PasswordNeverExpires $true