microsoft / Partner-Center-PowerShell

PowerShell module for managing Partner Center resources.
https://docs.microsoft.com/powershell/partnercenter/
MIT License
131 stars 60 forks source link

PSLicenseAssignment.cs ExcludedPlans missing set #139

Closed blakejakopovic closed 4 years ago

blakejakopovic commented 5 years ago

Steps to reproduce

$License = New-Object -TypeName Microsoft.Store.PartnerCenter.PowerShell.Models.Licenses.PSLicenseAssignment
$Licenses = New-Object -TypeName Microsoft.Store.PartnerCenter.PowerShell.Models.Licenses.PSLicenseUpdate
$License.SkuId = 'works fine'
$license.ExcludedPlans = 'THIS FAILS'

Expected behavior

You should be able to set excluded plans when assigning a user license.

Output should be $license.ExcludedPlans is set with the provided value. The current behavior conflicts with the source comment:

https://github.com/microsoft/Partner-Center-PowerShell/blob/1984dbf7edd25204c2ecdeca160f1d72bc731ac0/src/PowerShell/Models/Licenses/PSLicenseAssignment.cs#L38-L40

Actual behavior

'ExcludedPlans' is a ReadOnly property.
At line:4 char:3
+   $license.ExcludedPlans = 'THIS FAILS'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Diagnostic logs

N/A

Environment

PowerShell Version: 5.1.14409.1018 Module Version: 1.5.1907.2

ghost commented 5 years ago

@blakejakopovic you can use the add function on that property to add the plans that should be excluded. An example of this would look something like

# Create the objects that will be needed
$license = New-Object -TypeName Microsoft.Store.PartnerCenter.PowerShell.Models.Licenses.PSLicenseAssignment
$licenses = New-Object -TypeName Microsoft.Store.PartnerCenter.PowerShell.Models.Licenses.PSLicenseUpdate
# Find the SkuId of the license we want to add - in this example we will use the O365_BUSINESS_PREMIUM license
$license.SkuId = (Get-PartnerCustomerLicense -CustomerId '46a62ece-10ad-42e5-b3f1-b2ed53e6fc08' | Where-Object -Property SkuPartNumber -Value "O365_BUSINESS_PREMIUM" -EQ).SkuId

# Add the license to the update statement. 
$licenses.LicensesToAssign.Add($license)

$licenses.ExcludedPlans("SHAREPOINTWAC")

# Call the command to update the license assignment. 
Set-PartnerCustomerUserLicense -CustomerId '46a62ece-10ad-42e5-b3f1-b2ed53e6fc08' -LicenseUpdate $licenses -UserId '67e57a6a-6f26-4d6c-af64-533bb7f6a99e'
blakejakopovic commented 5 years ago

@isaiahwilliams How does that work with licenses that have conflicting/competing plans?

An example is as follows: "You will have to expand the Business Essentials node and switch OFF “SharePoint Online (Plan 1)” because the Dynamics Licence includes “SharePoint Online (Plan 2)” and only one can be enabled at a time."

What happens if not all users have a Dynamics License, so you want to keep the SharePoint Online (Plan 1) plan for them? Storing a per tenant config of excluded plans isn't granular enough, we need a per license sku (per tenant) configuration.

Ideally a single API call can set any license specific disabled plans for assignments. And It is possible to use GUIDs for ExcludedPlans?

ghost commented 5 years ago

@blakejakopovic with this approach you are turning on, or off, features associated with a specific license. So, if you have overlapping features due to the licenses assigned to the user then when you perform the update the operation will be scoped to the specific license. Let me review the command to see if there anything that can be done to remove some of the operational complexity that is there today.

ghost commented 4 years ago

We are continually looking to improve the module. Since this feature is working we will not make any changes to this functionality in the 3.0 version of the module. As plans form for future update we will be sure to evaluate how best to to simplify license management at the point in time.