So basically I am current using this script that checks what license is assigned to each account in Azure AD
Connect-MsolService
$Users= Import-CSV C:\Users\Ark\Desktop\powershell\test01.csv
$Users|%{Get-MsolUser -UserPrincipalName $_.UPN|select userPrincipalNAme,@{n="Licenses Type";e={$_.Licenses.AccountSKUid}}}
The csv file that I am ingesting looks like this
|UserPrincipalName|
|:----------------------|
|test.user@test.com |
|test.user2@test.com |
|test.user1@test.com |
With this scripts it goes through and outputs the correct license info for each account, like so
|UserPrincipalName| Licenses Type
|:----------------------|:-------------
|[email protected] |testdomain:SPE_E3
|[email protected] |testdomain:SPE_F1
|[email protected] |testdomain:SPE_E3
Where I am stuck at is I would like for this to only output users that only have a specific type of license. For example if I would only want users that have a testdomain:SPE_E3 license assigned. What can I do to edit my script that would only output users for that specific license, like so
|UserPrincipalName| Licenses Type
|:----------------------|:-------------
|[email protected] |testdomain:SPE_E3
|[email protected] |testdomain:SPE_E3
CodePudding user response:
Try with the "Where-Object" filter as follows:
Where-Object {($_.licenses).AccountSkuId -match "SPE_E3"}