Counting O365 License Service Plans

Hello Everyone,

I’m having some trouble trying to count specific Service Plans for O365 Licenses. I was tasked with find all users who still have My Analytics enabled in our tenant. I started by digging down the levels of Get-MsolUser until I got here:

 

PS C:\Users\rmartin> (Get-MsolUser -UserPrincipalName me@mydomain.com).Licenses.ServiceStatus.ServicePlan.ServiceName
MCOMEETADV
POWER_VIRTUAL_AGENTS_O365_P2
CDS_O365_P2
PROJECT_O365_P2
DYN365_CDS_O365_P2
MICROSOFTBOOKINGS
KAIZALA_O365_P3
MICROSOFT_SEARCH
WHITEBOARD_PLAN2
MIP_S_CLP1
MYANALYTICS_P2
BPOS_S_TODO_2
FORMS_PLAN_E3
STREAM_O365_E3
Deskless
FLOW_O365_P2
POWERAPPS_O365_P2
TEAMS1
PROJECTWORKMANAGEMENT
SWAY
INTUNE_O365
YAMMER_ENTERPRISE
RMS_S_ENTERPRISE
OFFICESUBSCRIPTION
MCOSTANDARD
SHAREPOINTWAC
SHAREPOINTENTERPRISE
EXCHANGE_S_ENTERPRISE
EXCHANGE_S_FOUNDATION
INTUNE_A_VL
ADALLOM_S_DISCOVERY
EXCHANGE_S_FOUNDATION
AAD_PREMIUM
MFA_PREMIUM
EXCHANGE_S_FOUNDATION
BI_AZURE_P2
ONEDRIVE_BASIC
VISIOONLINE
EXCHANGE_S_FOUNDATION
VISIO_CLIENT_SUBSCRIPTION
EXCHANGE_S_FOUNDATION
BI_AZURE_P0

So I’m happy with what I see there, so I I’d like to filter it. So I try this:

PS C:\Users\rmartin> (Get-MsolUser -UserPrincipalName me@mydomain.com).Licenses.ServiceStatus | ? $_.Licenses.ServiceStatus.ServicePlan.ServiceName -like "MYANALYTICS*"
Where-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:85
+ ... eStatus | ? $_.Licenses.ServiceStatus.ServicePlan.ServiceName -like " ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Where-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WhereObjectCommand

As you can see, it’s now not too happy with me. I know this is going to be something very simple, but can someone explain to me what I’m doing wrong?

 

Thanks,

-Rob M

You're close.
It's throwing an exception because the Where-Object is refencing a non-existent "Licences" member of the current pipeline object. Basically, you've doubled up the object in your pipeline.
Licenses.ServiceStatus does not contain "Licenses" member.
This will work:
Get-MsolUser |
    Where-Object -FilterScript {
        $_.Licenses.ServiceStatus |
        Where-Object -FilterScript {
            $_.ServicePlan.ServiceName -match "^MYANALYTICS" -and $_.ProvisioningStatus -eq "Success"
        }
    }