检查Office 365中的用户许可证分配

时间:2015-08-05 21:09:43

标签: powershell azure office365

如何修复此脚本。我正在尝试获取使用Import-CSV输入的用户列表的许可证状态,然后实习将结果导出到单独的CSV文件。目前这对我来说不太合适。感谢您的帮助/建议:-)

Import-Module MSOnline
Connect-MSOLService -Credential $cred
$path = "C:\Scripts\Interns.csv"
$users = Import-Csv $path
$users | ForEach-Object` 
{
Get-MsolUser | Select UserPrincipalName, IsLicensed | Export-Csv "C:\Scripts\isLicensed.csv"
}

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

Import-Module MSOnline
Connect-MSOLService -Credential $cred
$path = get-content C:\Scripts\Interns.csv

Foreach ($user in $path){
   $a = get-msoluser -UserPrincipalName $user | select userprincipalname, isLicensed
   $licensed = $a.isLicensed
   $u = $a.userprincipalname
   $result = $u +","+ $licensed
   Add-Content c:\Scripts\isLicensed.csv $result
}