SHARE
TWEET

Untitled

a guest Oct 15th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ADusers = Get-ADUser -filter * -Properties proxyaddresses,givenname,surname,samaccountname,userprincipalname,mail -SearchBase "OU=Users,OU=LAB,DC=ad,DC=lab,DC=se"
  2. $Forestsuffix = $((Get-ADforest).upnsuffixes[0]).tolower()
  3.  
  4. $Deleteusersonerror = $true
  5.  
  6.  
  7. foreach ($ADuser in $ADusers) {
  8.  
  9.     if (!$ADuser.GivenName)
  10.  {
  11.         Write-Host "Firstname is not configured on user $($ADuser.name). Script will abort next check for this user" -ForegroundColor Red
  12.       continue  }
  13.      
  14.        
  15.     if (!$ADuser.Surname)
  16.  {
  17.         Write-Host "Surname is not configured on user $($ADuser.name) Script will abort next check for this user" -ForegroundColor Red
  18.     continue    }
  19.  
  20.  
  21.  
  22.  
  23.  $expectedUPN = (($ADuser.GivenName.ToLower())+"."+($ADuser.Surname.ToLower())+$Forestsuffix)
  24.  
  25.  
  26.    IF (!($ADuser.proxyaddresses | ? {$PSitem -CMatch "SMTP:$expectedUPN"})) {
  27.  
  28.         Write-host "$($ADuser.name) does not have a correct PRIMARY proxy addresses configured" -ForegroundColor Yellow
  29.         #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
  30.        }
  31.        
  32.        
  33.    IF (!($ADuser.mail | ? {$PSItem -match $expectedUPN})) {
  34.  
  35.         Write-Host "$($ADuser.name) does not have a correct Mail configured" -ForegroundColor Blue
  36.         #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
  37.         }
  38.  
  39.  
  40.    IF (!($ADuser.UserPrincipalName | ? {$PSItem -match $expectedUPN})) {
  41.  
  42.         Write-Host "$($ADuser.name) does not have a correct UPN configured" -ForegroundColor DarkRed
  43.         #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
  44.         }
  45.  
  46.    IF (!($ADuser.proxyaddresses | ? {$PSitem -CMatch "smtp:"+$($ADuser.SamAccountName)})) {
  47.  
  48.         Write-host "$($ADuser.name) does not have a correct Secondary proxy addresses configured" -ForegroundColor Yellow
  49.         #if ($Deleteusersonerror) {Remove-ADUser $ADuser -Confirm:$false}
  50.        }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.    
  65.    $Secondaryproxy = ($ADuser.proxyaddresses | ? {$PSitem -CMatch "smpt:" -match $PSitem.samaccountname})
  66.    if (!$Primaryproxy) {
  67.         #DO NOTHING
  68.  
  69.         Write-host "$($ADuser.ObjectGUID) does not have a matching secondary addresses to the SAMAccountname" -ForegroundColor Yellow
  70.  
  71.      
  72. }
  73.  
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top