Advertisement
Guest User

Untitled

a guest
Oct 10th, 2012
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##======================================================================================
  2. ##Script:  EnableLyncUsers.ps1
  3. ##Author:  Josh Reichardt
  4. ##Email:   jreichardt@gmrc.com
  5. ##Date:    10/9/12
  6. ##Purpose: Use this script to add users already in AD domain into Lync 2010 environment.
  7. ##Notes:   Reads in a CSV file with pre populated AD Display names.  Can be adjusted to
  8. ##         work with alternate AD names (eg SIP address, UPN or AD log on name).
  9. ##======================================================================================
  10.  
  11. #Variables.
  12. $File = "C:\Lync\test.csv"
  13. $Log = New-Item -ItemType File -Path "C:\Lync\userlog.txt" -Force
  14.  
  15. #Import CSV File
  16. $UserArray = Import-CSV -Path $File
  17.  
  18. #Check if user file is empty.
  19. if ($UserArray -eq $null)
  20. {
  21.      write-host "No Users Found in Input File"
  22.      exit 0
  23. }
  24.  
  25. #Get total number of users in CSV file and begin proccessing.
  26. $count = $UserArray | Measure-Object | Select-Object -expand count
  27. Write-Host "Found " $count "Users to import."
  28. Write-Host "Processing Users.....`n"
  29. $index = 1
  30.  
  31. ForEach ($User in $UserArray) {
  32.    
  33.     Write-Host "Processing User " $index " of " $count
  34.     $Fullname = $User.DisplayName
  35.     $aduser = get-csaduser -Identity $Fullname
  36.    
  37.     #Check if user is in AD.  Log if they are NOT.
  38.     if ($aduser -eq $null) {
  39.         $notinad = $true
  40.         Write-Host "User " $Fullname " is not in AD.  Double check spelling, etc." -Foregroundcolor Red
  41.         Add-Content -Path $Log -Value "$($Fullname) is not in AD.  Double check spelling, etc."
  42.     }
  43.    
  44.     else {
  45.         $notinad = $false
  46.     }
  47.    
  48.     #If user is in AD check if enabled in Lync and log if enabled.
  49.     if ($aduser.Enabled) {
  50.         Write-Host $User.DisplayName "is already enabled in Lync, skipping."  -Foregroundcolor Yellow
  51.         Add-Content -Path $Log -Value "$($Fullname) is already enabled in Lync."
  52.     }      
  53.  
  54.     #User not enabled.
  55.     else {
  56.         Write-Host "Adding user " $User.DisplayName -Foregroundcolor Green
  57.         Enable-CsUser -Identity $User.DisplayName -Registrarpool "lyncpoolGMRC.gmrcnt.local" -SipAddressType Emailaddress
  58.    
  59.         #Check if last command failed.  If it does, log it.
  60.         if(!$?) {
  61.             Add-Content -Path $Log -Value "$($Fullname) not enabled.  $(Get-Date)$($error[0])"
  62.             continue
  63.         }
  64.        
  65.     }
  66.  
  67.     $index++   
  68.    
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement