通过某个许可获取msoluser

时间:2016-09-27 15:42:59

标签: powershell office365

我试图通过某个许可证通过get-msoluser获取办公室365的用户。出于某种原因,我无法让它工作,因为$ user没有返回任何内容。我也是积极的,它也是正确的许可证。关于出了什么问题的任何想法。

$c = Get-Credential
Connect-MsolService -Credential $c
$accountsku = Get-MsolAccountSku
$userMSOL = Get-MsolUser -All | Where {$_.Licenses.AccountSku -eq $accountsku[0].AccountSkuId}

1 个答案:

答案 0 :(得分:1)

Licenses集合属性(包含多个值),因此您需要替换表达式:

Where {$_.Licenses.AccountSku -eq $accountsku[0].AccountSkuId}

Where { $_.Licenses.accountskuid -contains $accountsku[0].AccountSkuId }

示例

$c = Get-Credential
Connect-MsolService -Credential $c
$accountsku = Get-MsolAccountSku
$userMSOL = Get-MsolUser -All | where { $_.Licenses.accountskuid -contains $accountsku[0].AccountSkuId }