K B
asked on
PowerShell: Office 365: How to pass multiple license options from user input?
I am trying to pass the user's input to ...
meaning, $Sku and $Options
Unfortunately, the methods don't support op_addition.
Is there any methodology that would work for this?
Frankly I am not even sure if the parameter [switch] would work.
Thank you
Set-MsolUserLicense -Verbose -UserPrincipalName $_.UserPrincipalName -AddLicenses $SKU -LicenseOptions $Options
meaning, $Sku and $Options
Unfortunately, the methods don't support op_addition.
Is there any methodology that would work for this?
function Test-SentLicenses {
[CmdletBinding()]
Param
(
# Users to be licensed
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string[]] $Users,
[Parameter(Mandatory=$False)]
[switch]$E3,
[parameter(Mandatory=$False)]
[switch]$EMS,
[Parameter(Mandatory=$False)]
[string]$PowerBIPro,
[Parameter(Mandatory=$False)]
[string]$PowerBIIndividual,
[Parameter(Mandatory=$False)]
[switch]$PowerBIFree,
[Parameter(Mandatory=$False)]
[switch]$RMSAdhoc
)
Begin {
# Assign Tenant and Location to a variable
$Tenant = "SENT"
$Location = "US"
# Assign each AccountSkuID to a variable
$TenantE3 = ($Tenant + ':ENTERPRISEPREMIUM')
$TenantEMS = ($Tenant + ':EMSPREMIUM')
$TenantProBI = ($Tenant + ':POWER_BI_PRO')
$TenantIUserBI = ($Tenant + ':POWER_BI_INDIVIDUAL_USER')
$TenantFreeBI = ($Tenant + ':POWER_BI_STANDARD')
$TenantRMS = ($Tenant + ':RIGHTSMANAGEMENT_ADHOC')
# Zero out $Options
$Options = $null
if($E3.IsPresent){
$TenantE3 = ($Tenant + ':ENTERPRISEPREMIUM')
$LicenseE3 = New-MsolLicenseOptions -AccountSkuId $TenantE3
$Options += $LicenseE3
}
if($EMS.IsPresent){
$TenantEMS = ($Tenant + ':EMSPREMIUM')
$LicenseEMS = New-MsolLicenseOptions -AccountSkuId $TenantEMS
$Options += $LicenseEMS
}
if($PowerBIPro.IsPresent){
$LicenseProBI = New-MsolLicenseOptions -AccountSkuId $TenantProBI
$Options += $LicenseProBI
}
if($PowerBIIndividual.IsPresent){
$LicenseIUserBI = New-MsolLicenseOptions -AccountSkuId $TenantIUserBI
$Options += $LicenseIUserBI
}
if($PowerBIFree.IsPresent){
$LicenseFreeBI = New-MsolLicenseOptions -AccountSkuId $TenantFreeBI
$Options += $LicenseFreeBI
}
if($RMSAdhoc.IsPresent){
$LicenseRMS = New-MsolLicenseOptions -AccountSkuId $TenantRMS
$Options += $LicenseRMS
}
}
Process {
Set-MsolUser -UserPrincipalName $_.UserPrincipalName -UsageLocation $Location
Set-MsolUserLicense -Verbose -UserPrincipalName $_.UserPrincipalName -AddLicenses $SKU -LicenseOptions $Options
}
End {
}
}
Frankly I am not even sure if the parameter [switch] would work.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is a revised and shortened example:
Open in new window