Reputation: 477
I am trying to filter for the output from this command (Get-MsolUser -UserPrincipalName ).Licenses.ServiceStatus
Which looks like this:
ServicePlan ProvisioningStatus
----------- ------------------
MCOMEETADV Success
ADALLOM_S_DISCOVERY Disabled
EXCHANGE_S_FOUNDATION PendingProvisioning
AAD_PREMIUM Success
MFA_PREMIUM Success
ONEDRIVE_BASIC Success
VISIOONLINE Success
EXCHANGE_S_FOUNDATION PendingProvisioning
VISIO_CLIENT_SUBSCRIPTION Success
MCOPSTN1 Success
EXCHANGE_S_FOUNDATION PendingProvisioning
DYN365_CDS_VIRAL Success
FLOW_P2_VIRAL Success
EXCHANGE_S_FOUNDATION PendingProvisioning
INTUNE_A PendingInput
EXCHANGE_S_FOUNDATION PendingProvisioning
BI_AZURE_P2 Success
MCOEV Success
MICROSOFT_SEARCH PendingProvisioning
WHITEBOARD_PLAN2 PendingProvisioning
MIP_S_CLP1 PendingProvisioning
MYANALYTICS_P2 Success
BPOS_S_TODO_2 Success
FORMS_PLAN_E3 Success
STREAM_O365_E3 Success
Deskless Success
FLOW_O365_P2 Success
POWERAPPS_O365_P2 Success
TEAMS1 Success
PROJECTWORKMANAGEMENT Success
SWAY Success
INTUNE_O365 PendingActivation
YAMMER_ENTERPRISE Success
RMS_S_ENTERPRISE Success
OFFICESUBSCRIPTION Success
MCOSTANDARD Success
SHAREPOINTWAC Success
SHAREPOINTENTERPRISE Success
EXCHANGE_S_ENTERPRISE Success
I'm filtering for Exchange_S_Enterprise and MCOEV.
I've tried (Get-MsolUser -UserPrincipalName ).Licenses.ServiceStatus | Select-Object Exchange
I've tried Where-Object
Which returns nothing
(Get-MsolUser -UserPrincipalName ).Licenses.ServiceStatus
I'd like to do an if statement, to continue my script if EXCHANGE_S_ENTERPRISE's provisioning status -eq "Success"
Upvotes: 0
Views: 672
Reputation: 10333
If you digged into Service Status for one of your user, you would have seen that ServiceStatus is an object which contains several sublevels.
You need to get to the ServiceName to do your Where
statement..
Here's a working example of this that will perform different actions on both MCOEV and Exchange_S_Enterprise if their provisionning status is SUCCESS
.
$User = Get-MsolUser -UserPrincipalName '[email protected]'
$PlanstoCheck = @('MCOEV', ' EXCHANGE_S_ENTERPRISE')
$Plans = $User.Licenses.ServiceStatus.where( { $_.ServicePlan.ServiceName -in $PlanstoCheck })
Foreach ($Plan in $Plans) {
if ($Plan.ProvisioningStatus -eq 'SUCCESS') {
switch ($Plan.ServicePlan.ServiceName) {
'MCOEV' { Write-Host 'Do thing #1' }
'EXCHANGE_S_ENTERPRISE' { 'Do THing #2' }
}
}
}
When debugging, you can use F8 to execute only one line at a time.
In your case, loading a MSOL user at $User.Licenses.ServiceStatus, you can see there's a few level deeper. If you do a GetType()
at that level, you'll also notice your current level is not a string, but yet another object, hence why comparing an object to a string did not produce the expected result.
Upvotes: 0