Advertisement
Guest User

Untitled

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