Forum Discussion
powershell and Microsoft.Online: how to filter users with multiple conditions
- Jul 12, 2022
Here's an example using the Get-MsolUser commandlet you're using.
Get-MsolUser is limited to client-side filtering making it less ideal for larger environments.
I'd normally provide an example using server-side filtering, but this gets a bit more complicated in this instance so I'm going to skip it unless you're interested in this approach. Given all your other questions have remained aligned to the MSOnline module, this seems a safe assumption for now.
Get-MsolUser | Where-Object { $Skus = $_.Licenses.AccountSku.SkuPartNumber; if ($Skus -notcontains "ATP_ENTERPRISE" -and ($Skus -contains "O365_BUSINESS_ESSENTIALS" -or $Skus -contains "O365_BUSINESS_PREMIUM")) { $true }; }Cheers,
Lain
Here's an example using the Get-MsolUser commandlet you're using.
Get-MsolUser is limited to client-side filtering making it less ideal for larger environments.
I'd normally provide an example using server-side filtering, but this gets a bit more complicated in this instance so I'm going to skip it unless you're interested in this approach. Given all your other questions have remained aligned to the MSOnline module, this seems a safe assumption for now.
Get-MsolUser |
Where-Object {
$Skus = $_.Licenses.AccountSku.SkuPartNumber;
if ($Skus -notcontains "ATP_ENTERPRISE" -and ($Skus -contains "O365_BUSINESS_ESSENTIALS" -or $Skus -contains "O365_BUSINESS_PREMIUM")) { $true };
}
Cheers,
Lain
- mfranhind115Jul 12, 2022Brass Contributor
EX-CEL-LENT Lain!!!!!!
you won a couple of dinner my friend!!!!
thanks a lot for your precious help
I enjoied adding some info like this:Get-MsolUser | Select-Object UserPrincipalName, DisplayName, licenses, islicensed | Where-Object { $Skus = $_.Licenses.AccountSku.SkuPartNumber; if ($Skus -notcontains "ATP_ENTERPRISE" -and ($Skus -contains "O365_BUSINESS_ESSENTIALS" -or $Skus -contains "O365_BUSINESS_PREMIUM")) { $true }; }