Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set-ExecutionPolicy RemoteSigned
  2. Import-Module SkypeOnlineConnector
  3.  
  4. $credential = Get-Credential
  5. Connect-MsolService -Credential $credential
  6. $sfboSession = New-CsOnlineSession -Credential $credential
  7. Import-PSSession $sfboSession
  8.  
  9.  
  10. $numFiles = 0
  11. $files = Get-ChildItem -Path *.csv
  12.  
  13. Write-Host "Please enter one of the following options:"
  14. Write-Host "    1 - Add Regular User"
  15. Write-Host "    2 - Add Users From File"
  16.  
  17. $Option = Read-Host "   Choice"
  18.  
  19. if ($Option){
  20.     if ($Option -eq "1"){
  21.  
  22.         $first = Read-Host "First Name "
  23.         $last = Read-Host "Last Name "
  24.         $phone = Read-Host "Phone Number (just the digits eg ##########) "
  25.        
  26.         $content = @{first = $first; last = $last; phone = $phone}
  27.     }
  28.    
  29.     if ($Option -eq "2"){
  30.        
  31.         Write-Host "Please choose a file, or enter the full path of the file you would like to load."
  32.         Write-Host "If there are any spaces in the path please use quotation marks around the entire path."
  33.                
  34.         if ($files){
  35.             foreach ($file in $files){
  36.                 Write-Host "["$numFiles"] - "$file
  37.                 $numFiles++
  38.             }
  39.         }
  40.         $opt = Read-Host
  41.                
  42.         if ($opt -In 0..$numFiles){ $content = Import-CSV $files[$opt] }
  43.         else { if (Test-Path -Path $opt){ $content = Import-CSV $opt } }
  44.  
  45.     }
  46.  
  47. }
  48.  
  49. foreach ($item in $content){
  50.  
  51.     $licenses = Get-MsolAccountSku | Where-Object AccountSkuId -like "reseller-account:ENTERPRISEPACK"
  52.     $totLicenses = $licenses.ActiveUnits - $licenses.ConsumedUnits
  53.  
  54.     $userName = $item.first.Substring(0,1) +'.'+ $item.last
  55.     $UPN = $userName + '@domain.com'
  56.  
  57.     $isOnline = Get-MsolUser -UserPrincipalName $UPN
  58.     if ($isOnline){
  59.         if ($totLicenses -le 0){
  60.             Write-Host"No Licenses Available for user $UPN."
  61.         } else {
  62.             Get-PSSession | Connect-PSSession
  63.             if ($isOnline.IsLicensed -eq $False -and $UPN -eq $isOnline.UserPrincipalName){
  64.                 Write-Host "No licenses found on $UPN, applying."
  65.                 Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:ENTERPRISEPACK"
  66.                 Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:MCOEV"
  67.                 Add-Content -Path c:\temp\$toCheck"Status".txt -Value ("License added to account "+ $UPN)
  68.             } else {
  69.                 Write-Host "Applying phone license for $UPN and waiting five minutes."
  70.                 Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:MCOEV"
  71.                 Add-Content -Path c:\temp\$toCheck"Status".txt -Value ($UPN+" Applied phone system license.")
  72.                 Start-Sleep -s 300
  73.             }
  74.             Write-Host "Adding phone number to $UPN."
  75.             $num = "tel:+1"+$item.Phone
  76.             Set-CsUser $UPN -EnterpriseVoiceEnabled $true -HostedVoicemail $true -OnPremlineURI $num
  77.             #$isset = Get-CsOnlineUser $UPN | fl *Voice*, *PSTN*, *lineuri*, home*
  78.             Write-Host "Waiting for license to apply."
  79.             Start-Sleep -s 30
  80.             set-CsUserPstnSettings $UPN -HybridPstnSite domsite-1
  81.         }
  82.     } else {
  83.         Add-Content -Path c:\temp\$toCheck"Status".txt -Value ("User $UPN doesn't exist, please create.")
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement