Script to add an Office 365 license with custom licensing options

<# .SYNOPSIS Adds Office 365 Licenses to selected users .DESCRIPTION Adds Office 365 Licenses to selected users This script can be executed on any machine that has the MSOnline module installed. .EXAMPLE Add-DOJO365License -EmailAddress -licenses PDT:STANDARDPACK .EXAMPLE Add-DOJO365License -EmailAddress -licenses PDT:ATP_ENTERPRISE,PDT:FLOW_FREE #>
Function Add-DOJO365License {

        [string]$licenses = "PDT:STANDARDPACK"

    Import-Module MSonline    
    Write-Verbose "$licenses"
    Write-Verbose $emailaddress    
    if((Get-MsolUser -UserPrincipalName $emailaddress).islicensed){
        Set-MsolUserLicense -UserPrincipalName $emailaddress -RemoveLicenses $licenses
    if($licenses = "PDT:STANDARDPACK" ){
        $LO = New-MsolLicenseOptions -AccountSkuId $licenses -DisabledPlans  "YAMMER_ENTERPRISE" , "MCOSTANDARD" , "SHAREPOINTSTANDARD" , "SHAREPOINTWAC"
        Set-MsolUser -UsageLocation 'AU' -UserPrincipalName $emailaddress
        Set-MsolUserLicense -UserPrincipalName $emailaddress -LicenseOptions $LO -AddLicenses $licenses -Verbose
        Set-MsolUser -UsageLocation 'AU' -UserPrincipalName $emailaddress
        Set-MsolUserLicense -UserPrincipalName $emailaddress -AddLicenses $licenses -Verbose

$EmailAddress = ""
Add-DOJO365License -EmailAddress $emailaddress 

Using PowerShell to connect to Office 365 when a proxy blocks your authentication

Sometimes PowerShell does not have access to the internet because there is a proxy in the way. This can be a problem when you are trying to update help or authenticate to a cloud service provider like Office 365.

The way to get around this is to use a session option.

$cred = Get-Credential
$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “” `
-Credential $Cred -Authentication Basic -AllowRedirection -SessionOption` $proxysettings Import-PSSession $Session -AllowClobber -Prefix o365

This assumes that you can browse using internet explorer and that your account has the correct access in Office 365. Also in this example I am using the prefix O365 to distinguish this session from the On premises session.