Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ADusers = Get-ADUser -filter * -Properties proxyaddresses,givenname,surname,samaccountname,userprincipalname,mail -SearchBase "OU=Users,OU=LAB,DC=ad,DC=lab,DC=se"
- $Forestsuffix = $((Get-ADforest).upnsuffixes[0]).tolower()
- $Deleteusersonerror = $true
- foreach ($ADuser in $ADusers) {
- if (!$ADuser.GivenName)
- {
- Write-Host "Firstname is not configured on user $($ADuser.name). Script will abort next check for this user" -ForegroundColor Red
- continue }
- if (!$ADuser.Surname)
- {
- Write-Host "Surname is not configured on user $($ADuser.name) Script will abort next check for this user" -ForegroundColor Red
- continue }
- $expectedUPN = (($ADuser.GivenName.ToLower())+"."+($ADuser.Surname.ToLower())+$Forestsuffix)
- IF (!($ADuser.proxyaddresses | ? {$PSitem -CMatch "SMTP:$expectedUPN"})) {
- Write-host "$($ADuser.name) does not have a correct PRIMARY proxy addresses configured" -ForegroundColor Yellow
- #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
- }
- IF (!($ADuser.mail | ? {$PSItem -match $expectedUPN})) {
- Write-Host "$($ADuser.name) does not have a correct Mail configured" -ForegroundColor Blue
- #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
- }
- IF (!($ADuser.UserPrincipalName | ? {$PSItem -match $expectedUPN})) {
- Write-Host "$($ADuser.name) does not have a correct UPN configured" -ForegroundColor DarkRed
- #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
- }
- IF (!($ADuser.proxyaddresses | ? {$PSitem -CMatch "smtp:"+$($ADuser.SamAccountName)})) {
- Write-host "$($ADuser.name) does not have a correct Secondary proxy addresses configured" -ForegroundColor Yellow
- #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
- }
- $Secondaryproxy = ($ADuser.proxyaddresses | ? {$PSitem -CMatch "smpt:" -match $PSitem.samaccountname})
- if (!$Primaryproxy) {
- #DO NOTHING
- Write-host "$($ADuser.ObjectGUID) does not have a matching secondary addresses to the SAMAccountname" -ForegroundColor Yellow
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement