Reputation: 4278
I am trying to get users in office 365 by get-msoluser by a certain license. For some reason I cannot get it to work in the sense that The $user is returning nothing. I am also posistive that it is the correct license as well. Any ideas on what going wrong.
$c = Get-Credential
Connect-MsolService -Credential $c
$accountsku = Get-MsolAccountSku
$userMSOL = Get-MsolUser -All | Where {$_.Licenses.AccountSku -eq $accountsku[0].AccountSkuId}
Upvotes: 1
Views: 3001
Reputation: 59318
Licenses
is a collection property (contain multiple values), so you need to replace the expression:
Where {$_.Licenses.AccountSku -eq $accountsku[0].AccountSkuId}
with
Where { $_.Licenses.accountskuid -contains $accountsku[0].AccountSkuId }
Example
$c = Get-Credential
Connect-MsolService -Credential $c
$accountsku = Get-MsolAccountSku
$userMSOL = Get-MsolUser -All | where { $_.Licenses.accountskuid -contains $accountsku[0].AccountSkuId }
Upvotes: 1