Jul 12 2022 06:53 AM - edited Jul 12 2022 06:54 AM
Hi all,
I'm connected to my Tenant and several domains under it
I would need to extract only user having
license O365_BUSINESS_ESSENTIALS or O365_BUSINESS_PREMIUM
and
not having ATP_ENTERPRISE
I started with a command like this:
Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "O365_BUSINESS_PREMIUM"}
but I'm struggling to combine multiple conditions...
thanks for your help
Jul 12 2022 08:01 AM
Solution
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
Jul 12 2022 08:09 AM - edited Jul 12 2022 08:11 AM
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 };
}
Jul 12 2022 08:01 AM
Solution
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