If an account is created and assigned a license, the administrator can still disable individual services. The typical scenario where this is useful is giving access to a consultant who may need to access multiple services, while ensuring their email will be managed externally.
To remove Exchange from a license, we also rely on the Set-MsolUserLicense command using the LicenseOptions parameter (which takes a list of services to disable).
The New-MsolLicenseOptions command creates a LicenseOptions record that targets a particular license with a list of disabled services (in the DisabledPlan parameter). You then pass these options to the Set-MsolUserLicense command:
$opt = New-MsolLicenseOptions -AccountSkuId "mytest321:ENTERPRISEPACK"
-DisabledPlans "EXCHANGE_S_ENTERPRISE"
Set-MsolUserLicense -UserPrincipalName [email protected]
-LicenseOptions $opt
You can validate the effective services for the account by querying ServiceStatus of the user's Licenses property:
$user = Get-MsolUser -UserPrincipalName [email protected]
$user.Licenses.ServiceStatus
ServicePlan ProvisioningStatus
----------- ------------------
FORMS_PLAN_E3 PendingProvisioning
STREAM_O365_E3 PendingProvisioning
....
SHAREPOINTENTERPRISE Success
EXCHANGE_S_ENTERPRISE Disabled
To enable the service (and trigger the creation of a mailbox), you simply pass a new LicenseOption record without a disable plan parameter:
$opt = New-MsolLicenseOptions -AccountSkuId "mytest321:ENTERPRISEPACK"
Set-MsolUserLicense -UserPrincipalName [email protected]
-LicenseOptions $opt
The status of the service might be PendingInput, immediately following the execution of the command, as it takes a few minutes for the mailbox to be created.