Script repository
The script checks whether the specified Microsoft 365 license is being assigned to a user within the current operation. To execute the script, use the If PowerShell script returns true condition in a business rule triggering Before modifying Microsoft 365 properties of a user.
In the script, the $licenseToCheck variable specifies the SKU Part Number of the Microsoft 365 license to check.
$licenseToCheck = "ENTERPRISEPACK" # TODO: modify me
# Get Microsoft 365 properties.
$microsoft365Properties = New-Object Softerra.Adaxes.Adsi.CloudServices.AdmM365AccountProperties
$microsoft365Properties.LoadFromPropertyList($Context.Action.PropertyList)
# Check license
$Context.ConditionIsMet = $False
foreach ($license in $microsoft365Properties.Licenses)
{
if (($license.Assigned) -and ($license.Sku.SkuPartNumber -eq $licenseToCheck))
{
$Context.ConditionIsMet = $True
return
}
}
Comments 10
You must be signed in to comment.
ComputerHabit
Doesn't work.
is empty.
Support
Hello,
What exactly is not working? Do you face any error messages? If so, please, provide us with screenshots. Also, please, provide us with the exact script you are using (with all your modifications) and a screenshot of the Business Rule executing the script.
Matt Chapman
Hi
I'm trying to use this but get 2 errors:
Exception calling "LoadFromPropertyList" with "1" argument(s): "Value cannot be null. Parameter name: propertyList" Stack trace: at , : line 5
The property 'ConditionIsMet' cannot be found on this object. Verify that the property exists and can be set. Stack trace: at , : line 8
Support
Hello Matt,
According to the error message, you are using the script in Run a program or PowerShell script action, not in the If PowerShell script returns true condition. It will not work as the script is specifically dedicated for the condition only.
Matt Chapman
Ahhh, got it. Thanks.
Kristoffer Again...
How can this script be modified to return whether the user already has a license, or one of multiple licenses assigned?
I want to check if an account has the necessary licenses (enterprisepack,enterprisepremum,exchangeenterprise) to it before doing a modification on it. So a powershell return true or false seems like a good option.
Support
Hello Kristoffer,
In the latest version of Adaxes, there is no need to use scripts to check Microsoft 365 licenses already assigned to a user. It can be done using the If is licensed for Microsoft 365 condition.
If you are using Adaxes 2020.1 or older, you can use the below script. For information on how to check the version of Adaxes you are currently using, have a look at the following help article: https://www.adaxes.com/help/CheckServiceVersion.
Kristoffer Again...
I actually realized you already had a condition for that. It is called Is licenced in Office 365 and there I could select the licenses.
Great solution, keep up the good work!
Juha Otava
Hello,
Added a business rule "Before modifying Microsoft 365 properties of a user" and it runs the custom command when updating user M365 licenses.
I always get this log entry: "Check M365 License being assigned: No operations executed".
It doesn't matter if license is assigned or not. SKU is correct.
Support
Hello Juha,
Sorry for the confusion, but we are not sure we understand your setup. Please, describe it in all the possible details with screenshots.
For your information, the script must be executed directly in a business rule triggering Before modifying Microsoft 365 properties of a user. It will never work in a custom command no matter where the command is executed.