iamkilo

SnipeADSync

Apr 11th, 2019
4,973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $users = Get-ADUser -Filter * -SearchBase "OU=All Users,DC=Contoso,DC=com" -Properties GivenName,Surname,Description,UserPrincipalName,telephoneNumber
  2.  
  3. $apikey = "supersecretapikey"
  4. $url = "snipeurl"
  5. $password = "INSERT_LONG_PASSWORD_HERE"
  6.  
  7. foreach ($user in $users)
  8. {
  9.     $snipeUser = Get-User -search $user.UserPrincipalName -url $url -apiKey $apikey
  10.     if(([string]::IsNullOrEmpty($snipeUser))) {
  11.         New-User -firstName $user.GivenName -lastName $user.Surname -userName $user.UserPrincipalName -password $password -password_confirmation $password -jobTitle $user.Description -phone $user.telephoneNumber -email $user.UserPrincipalName -url $url -apiKey $apikey
  12.     }
  13.    
  14.     Else {
  15.         Set-User -id $snipeUser.id -first_name $user.GivenName -last_name $user.Surname -jobtitle $user.Description -email $user.UserPrincipalName -phone $user.telephoneNumber -url $url -apiKey $apikey
  16.     }
  17.    
  18.  
  19. }
Advertisement
Add Comment
Please, Sign In to add comment