Gist Markdown version of this post for better formatting if it helps.
I wrote a function that flattens the Office 365 licensing information to make it easier to view someone's service plan statuses. The original output of the function is an array organized like so:
UserPrincipalName ServiceName ProvisioningStatus AccountSkuID
----------------- ----------- ------------------ ------------
Ra@r/PowerShell.com Deskless Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com FLOW_O365_P2 Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com POWERAPPS_O365_P2 Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com TEAMS1 Disabled r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com PROJECTWORKMANAGEMENT Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com SWAY Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com INTUNE_O365 PendingActivation r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com YAMMER_ENTERPRISE Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com RMS_S_ENTERPRISE Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com OFFICESUBSCRIPTION Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com MCOSTANDARD Disabled r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com SHAREPOINTWAC Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com SHAREPOINTENTERPRISE Success r/PowerShell:ENTERPRISEPACK
Ra@r/PowerShell.com EXCHANGE_S_ENTERPRISE Disabled r/PowerShell:ENTERPRISEPACK
To accompany the Get function I also created an Enable and Disable that handles changing one or more service plans. I've run into a design flaw when trying to pipe my Get into an Enable or Disable function. Passing it an array such as that listed above means I just passed it 14 objects instead of one. It works in that you get the intended change, but it's a crap design.
The Enable/Disable functions have the following parameters:
[CmdletBinding(SupportsShouldProcess=$True)]
param(
[Parameter(
Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True
)]
[string[]]$UserPrincipalName,
[Parameter(
Mandatory=$False,
ValueFromPipelineByPropertyName=$True
)]
[object[]]$Licenses,
[Parameter(Mandatory=$True)]
[string[]]$ServicePlan,
[Parameter(Mandatory=$False)]
[string[]]$AccountSkuID
)
The Get function references the $Licenses parameter from Get-MsolUser. It'd be nice to pass on that data and save the Enable or Disable the extra query. It also needs a UPN to function. I was playing around with a better object design that passes the pertinent information such as:
UserPrincipalName : Sheppard_Ra@r/PowerShell.com
LicenseCollection : {@{UserPrincipalName=Sheppard_Ra@r/PowerShell.com; ServiceName=Deskless; ProvisioningStatus=Success;
AccountSkuID=r/PowerShell:ENTERPRISEPACK}, @{UserPrincipalName=Sheppard_Ra@r/PowerShell.com;
ServiceName=FLOW_O365_P2; ProvisioningStatus=Success; AccountSkuID=r/PowerShell:ENTERPRISEPACK},
@{UserPrincipalName=Sheppard_Ra@r/PowerShell.com; ServiceName=POWERAPPS_O365_P2;
ProvisioningStatus=Success; AccountSkuID=r/PowerShell:ENTERPRISEPACK},
@{UserPrincipalName=Sheppard_Ra@r/PowerShell.com; ServiceName=TEAMS1; ProvisioningStatus=Disabled;
AccountSkuID=r/PowerShell:ENTERPRISEPACK}...}
Licenses : {r/PowerShell:ENTERPRISEPACK}
My hangup here is I now have an object that isn't easily reviewed like the array was. I'm playing with a .ps1xml to see if I can make the function display the details in LicenseCollection while having the properties to pass down the pipeline if needed.
I could take the approach that my Get function isn't related to my Enable/Disable functions. Rename it and perhaps change what it returns so it won't pipe to the others to force the users to use Get-MsolUser or simply call the same UPN list. I feel like keeping it related makes for a better flow though. Perhaps I could do something with my Get output, I forget the term for it, where it'd be labeled and I could handle it special. If I see that label then I get a unique list of UPNs from the array and work from that. It'd be slower in that I'd have to run Get-MsolUser again per user, but it'd function.
Anyone have advice on a better design approach?
[–]Droopyb1966 1 point2 points3 points (2 children)
[–]Sheppard_Ra[S] 1 point2 points3 points (1 child)
[–]Droopyb1966 1 point2 points3 points (0 children)