wackou

Recopy mail field in msRTCSIP-PrimaryUserAddress field

Oct 3rd, 2015
2,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Copier le champ mail dans msRTCSIP-PrimaryUserAddress d'un utilisateur Active Directory
  2. #
  3. #
  4. # Wackou
  5. # www.wackou.com
  6. #VARIABLES
  7. $global:SITE = $NULL #initilisation variable site
  8. $OU = "LDAP://DC=domaine,DC=local" #OU par defaut
  9. $FILTER = "(&(mail=*)(!(msRTCSIP-PrimaryUserAddress=sip:*@*)))" #filtre sur le champ mail, celui doit etre remplie et le champs SIP vide
  10. $global:SEARCHER = $NULL #initilisation variable recherche adsi
  11. $global:LogTime = Get-Date -Format "dd-MM-yyyy_HH-mm-ss" # obtenir la date dès le lancement pour LOG
  12. #FONCTIONS
  13. function recopy {
  14.     $SEARCHER.FindAll() | Foreach {
  15.         $user = $_.GetDirectoryEntry()
  16.             $user."msRTCSIP-PrimaryUserAddress"="sip:"+$user."mail" #recopie du champs mail dans SIP
  17.             $user.SetInfo() #on enregistre les informations
  18.             $user.mail >> C:\script\CopyMail2SIP_$LogTime.txt #log pour connaitre les comptes modifies
  19.         }
  20.        
  21.     }
  22. cls
  23. $SITE = Read-Host "Saisir le nom du site (1, 2, etc ...)" #saisie du site
  24. If ($SITE -eq '') { #verification si l'utilisateur a saisie qqch
  25.         write-host "Merci de saisir un site !"$OU -foregroundcolor white -backgroundcolor red
  26.         break
  27. }
  28. $OU = "LDAP://OU=People,OU=$SITE,DC=domaine,DC=local" #construction du chemin LDAP
  29. If ([adsi]::Exists($OU)) { #verification si le chemin LDAP est valide
  30.         write-host "Site selectionne :"$OU
  31.         $SEARCHER = New-Object adsisearcher([adsi]$OU , $FILTER) #construction de la recherche adsi
  32.         recopy #lancement de la fonction
  33. }
  34. Else {
  35.         Write-host "Ce site n'existe pas !"$OU -foregroundcolor white -backgroundcolor red
  36. }
Advertisement
Add Comment
Please, Sign In to add comment