# Get Domain UPN
Get-ADForest | Format-List UPNSuffixes
# Add Domain UPN
Get-ADForest | Set-ADForest -UPNSuffixes @{add=”windowspapst.de”}
# Delete Domain UPN
Get-ADForest | Set-ADForest -UPNSuffixes @{remove=”windowspapst.de”}
# User ohne UPN
Get-ADUser -Filter * -Properties * | Where-Object {-not $_.UserPrincipalName} | Select SamAccountName -exp SamAccountName
# User bei denen die UPN nicht die E-Mail ist
Get-ADUser -Filter {enabled -eq $true} -SearchBase ‘OU=TEST,OU=User,OU=DWP,DC=dwp,DC=local’ -Properties Name,SamAccountName,UserPrincipalName,EmailAddress |
Where { $_.UserPrincipalName -ne $_.EmailAddress } | Select Name,SamAccountName,UserPrincipalName,EmailAddress |
Export-Csv C:\Temp\WrongEmptyUPN.csv -NoTypeInformation
# UPNs auf Ebene einer OU löschen
Get-ADUser -Filter * -SearchBase “OU=TEST,OU=User,OU=DWP,DC=dwp,DC=local” | Set-ADUser -Clear UserPrincipalName
# Set UPN auf Ebene einer OU
$Domain=”dwp.local”
$Users=Get-ADUser -Filter * -SearchBase “OU=TEST,OU=User,OU=DWP,DC=dwp,DC=local” | Where-Object {$_.UserPrincipalName -notlike”*@*”}
foreach($User in $Users){
$UPN = $User.SamAccountName+”@”+$Domain
write-host “- New UPN: “$upn
Set-ADUser -Server DC1.dwp.local $User.SamAccountName -UserPrincipalName $UPN
}
# Change Suffix
$OldSuf = ‘dwp.local’
$NewSuf = ‘derwindowspapst.de’
$OU = “OU=TEST,OU=User,OU=DWP,DC=dwp,DC=local”
$DC = “DC1.dwp.local”
Get-ADUser -SearchBase $OU -filter * | ForEach-Object {
$ChangeUpn = $_.UserPrincipalName.Replace($OldSuf,$NewSuf)
$_ | Set-ADUser -Server $DC -UserPrincipalName $ChangeUpn
}