Forum Discussion

mfranhind115's avatar
mfranhind115
Brass Contributor
Jul 12, 2022
Solved

powershell and Microsoft.Online: how to filter users with multiple conditions

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...
  • LainRobertson's avatar
    Jul 12, 2022

    mfranhind115 

     

    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

Resources