Last active
September 16, 2016 21:30
-
-
Save jacksoneyton/ec84f64b23c636322c08c65c9b1bbda9 to your computer and use it in GitHub Desktop.
MSOL User License Assignment Tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
These steps are required once on your computer, not every time you connect. However, you'll likely need to install newer versions of the software periodically. | |
Install the 64-bit version of the Microsoft Online Services Sign-in Assistant: Microsoft Online Services Sign-in Assistant for IT Professionals RTW. | |
URL: http://go.microsoft.com/fwlink/p/?LinkId=286152 | |
Install the 64-bit version of the Windows Azure Active Directory Module for Windows PowerShell: Windows Azure Active Directory Module for Windows PowerShell (64-bit version). | |
URL: http://go.microsoft.com/fwlink/p/?linkid=236297 | |
#> | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null | |
Import-Module MSOnline | |
Import-Module ActiveDirectory | |
[System.Windows.Forms.MessageBox]::Show("You will now be prompted to enter your Microsoft Online administrative account credentials." , "ARRC Office365 License Assignment tool") | |
Connect-MsolService -Credential (Get-Credential) | |
$licenseskus = Get-MsolAccountSku | |
#Areyousure function. Alows user to select y or n when asked to exit. Y exits and N returns to main menu. | |
function main | |
{ | |
LicenseSelection | |
} | |
function areyousure | |
{ | |
$areyousure = [System.Windows.Forms.MessageBox]::Show("Are you sure you wish to exit this utility?" , "ARRC Office365 License Assignment tool" , 4) | |
if ($areyousure -eq "YES"){exit} | |
if ($areyousure -eq "NO"){mainmenu} | |
} | |
function LicenseSelection | |
{ | |
$MenuNum=1 | |
cls | |
echo " ARRC Office365 License Assignment Tool" | |
echo "---------------------------------------------------------" | |
echo " ARRC O365 License Assignment" | |
echo "---------------------------------------------------------" | |
echo "" | |
echo "You have the following licenses available" | |
foreach ($sku in $licenseskus) | |
{ | |
$skuname = "$MenuNum - "+($sku | select AccountSkuID).AccountSkuId | |
$ActiveLicenses = ($sku | select ActiveUnits).ActiveUnits | |
$ConsumedLicenses = ($sku | select ConsumedUnits).ConsumedUnits | |
$remaininglicenses = $ActiveLicenses - $ConsumedLicenses | |
$SkuDetails = $skuname + "`r`n Licenses Available: $remaininglicenses `r`n" | |
echo $SkuDetails | |
$MenuNum++ | |
} | |
echo "---------------------------------------------------------" | |
$licAnswer = read-host "Please select which license you'd like to apply [number only]" | |
if (!$licAnswer) | |
{ | |
$nothinginput = [System.Windows.Forms.MessageBox]::Show("ERROR: No selection was made" , "ARRC Office365 License Assignment tool", 5) | |
if($nothinginput -eq "RETRY"){LicenseSelection} | |
if($nothinginput -eq "CANCEL"){areyousure} | |
} | |
else { | |
$licAnswer = $licAnswer -1 | |
$licenseToAssign = ($licenseskus[$licAnswer]).AccountSkuId | |
UserSelection | |
} | |
} | |
function UserSelection | |
{ | |
cls | |
echo " ARRC Office365 License Assignment Tool" | |
echo "---------------------------------------------------------" | |
echo " ARRC O365 User Selection" | |
echo "---------------------------------------------------------" | |
echo "" | |
echo "" | |
$userAnswer = Read-Host "Please enter the username you wish to assign the license to" | |
if ($userAnswer -eq $null) | |
{ | |
$nothinginput = [System.Windows.Forms.MessageBox]::Show("ERROR: No Username Was Entered" , "ARRC Office365 License Assignment tool", 5) | |
if($nothinginput -eq "RETRY"){UserSelection} | |
if($nothinginput -eq "CANCEL"){areyousure} | |
} | |
else | |
{ | |
$MsolDefaultDomain = Read-Host "Please enter your Microsoft Online default Domain (eg. contoso.onmicrosoft.com)" | |
$MsolUPN = $userAnswer +"@"+$MsolDefaultDomain | |
$MsolUser = get-msoluser -userprincipalname $MsolUPN | |
$newupn = ($MsolUser.ProxyAddresses | where-object {$_ -cmatch "SMTP"} ) -replace "SMTP:","" | |
$SIP_ADDomain = Read-Host "Please enter your ActiveDirectory domain (eg. contoso.local)" | |
$SIP_ADUPN = $userAnswer +"@"+$SIP_ADDomain | |
$SIP_Aduser = Get-ADUser -Filter {UserPrincipalName -Eq $SIP_ADUPN} -Properties mail | |
$SIP_newsip = "sip:$($SIP_Aduser.mail)" | |
AssignLicense | |
} | |
} | |
Function AssignLicense | |
{ | |
cls | |
echo " ARRC Office365 License Assignment Tool" | |
echo "---------------------------------------------------------" | |
echo " ARRC O365 License Assignment" | |
echo "---------------------------------------------------------" | |
echo "" | |
echo "" | |
$AssignmentAnswer = [System.Windows.Forms.MessageBox]::Show("License Selected: $LicenseToAssign `r`nUser account to apply license: $userAnswer `r`nWould you like to continue?" , "ARRC Office365 License Assignment tool", 3) | |
if($AssignmentAnswer -eq "YES") | |
{ | |
Set-MsolUserPrincipalName -NewUserPrincipalName $newupn -UserPrincipalName $MsolUser.UserPrincipalName | |
Set-ADUser $SIP_ADUser -replace @{'msRTCSIP-PrimaryUserAddress' = $SIP_newsip} | |
$MsolUserUPN = (get-msoluser -userprincipalname $newupn).UserPrincipalName | |
Get-MsolUser -UserPrincipalName $MsolUserUPN | Set-MsolUser -UsageLocation "US" | |
Set-MsolUserLicense -UserPrincipalName $MsolUserUPN -AddLicenses $LicenseToAssign -UsageLocation "US" | |
} | |
if($AssignmentAnswer -eq "NO"){LicenseSelection} | |
if($AssignmentAnswer -eq "CANCEL"){areyousure} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment