Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set-ExecutionPolicy RemoteSigned
- Import-Module SkypeOnlineConnector
- $credential = Get-Credential
- Connect-MsolService -Credential $credential
- $sfboSession = New-CsOnlineSession -Credential $credential
- Import-PSSession $sfboSession
- $numFiles = 0
- $files = Get-ChildItem -Path *.csv
- Write-Host "Please enter one of the following options:"
- Write-Host " 1 - Add Regular User"
- Write-Host " 2 - Add Users From File"
- $Option = Read-Host " Choice"
- if ($Option){
- if ($Option -eq "1"){
- $first = Read-Host "First Name "
- $last = Read-Host "Last Name "
- $phone = Read-Host "Phone Number (just the digits eg ##########) "
- $content = @{first = $first; last = $last; phone = $phone}
- }
- if ($Option -eq "2"){
- Write-Host "Please choose a file, or enter the full path of the file you would like to load."
- Write-Host "If there are any spaces in the path please use quotation marks around the entire path."
- if ($files){
- foreach ($file in $files){
- Write-Host "["$numFiles"] - "$file
- $numFiles++
- }
- }
- $opt = Read-Host
- if ($opt -In 0..$numFiles){ $content = Import-CSV $files[$opt] }
- else { if (Test-Path -Path $opt){ $content = Import-CSV $opt } }
- }
- }
- foreach ($item in $content){
- $licenses = Get-MsolAccountSku | Where-Object AccountSkuId -like "reseller-account:ENTERPRISEPACK"
- $totLicenses = $licenses.ActiveUnits - $licenses.ConsumedUnits
- $userName = $item.first.Substring(0,1) +'.'+ $item.last
- $UPN = $userName + '@domain.com'
- $isOnline = Get-MsolUser -UserPrincipalName $UPN
- if ($isOnline){
- if ($totLicenses -le 0){
- Write-Host"No Licenses Available for user $UPN."
- } else {
- Get-PSSession | Connect-PSSession
- if ($isOnline.IsLicensed -eq $False -and $UPN -eq $isOnline.UserPrincipalName){
- Write-Host "No licenses found on $UPN, applying."
- Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:ENTERPRISEPACK"
- Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:MCOEV"
- Add-Content -Path c:\temp\$toCheck"Status".txt -Value ("License added to account "+ $UPN)
- } else {
- Write-Host "Applying phone license for $UPN and waiting five minutes."
- Set-MsolUserLicense -UserPrincipalName "$UPN" -AddLicenses "reseller-account:MCOEV"
- Add-Content -Path c:\temp\$toCheck"Status".txt -Value ($UPN+" Applied phone system license.")
- Start-Sleep -s 300
- }
- Write-Host "Adding phone number to $UPN."
- $num = "tel:+1"+$item.Phone
- Set-CsUser $UPN -EnterpriseVoiceEnabled $true -HostedVoicemail $true -OnPremlineURI $num
- #$isset = Get-CsOnlineUser $UPN | fl *Voice*, *PSTN*, *lineuri*, home*
- Write-Host "Waiting for license to apply."
- Start-Sleep -s 30
- set-CsUserPstnSettings $UPN -HybridPstnSite domsite-1
- }
- } else {
- Add-Content -Path c:\temp\$toCheck"Status".txt -Value ("User $UPN doesn't exist, please create.")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement