Office 365 Licence使用情况统计

负责采购的同事需要知道目前公司使用了多少License,但是通过O365控制台界面似乎无法直接导出License使用量的信息,于是让我帮忙从后台统计一下。

$mail_text = Read-Host "输入你的Office 365邮箱:"
$pw_text = Read-Host "输入你的Office 365密码:"
$pw = ConvertTo-SecureString $pw_text -AsPlainText -Force 
$creds = New-Object -Typename System.Management.Automation.PSCredential -Argumentlist $mail_text, $pw
'请稍后,正在生成报告:'
connect-MsolService -Credential $creds
$result = Get-MsolUser | select userprincipalname,@{n='licenses';e={($_.licenses).AccountSkuId}} | sort licenses
'总计:' + ($result | Measure-Object).Count
'-其中-’
'协作版:' + ($result | where licenses -eq 'VobileChina:O365_BUSINESS_ESSENTIALS' | Measure-Object).Count
'高级版:' + ($result | where licenses -eq 'VobileChina:O365_BUSINESS_PREMIUM' | Measure-Object).Count
'未分配:' + ($result | where licenses -eq $null | Measure-Object).Count
$result | Export-Csv -Path ./o365usage.csv -Encoding Default

2017-3-15更新:

换了新工作,公司用的是国际版Office 365,License的类型似乎和世纪互联的不一样,存在一个人拥有多个授权的情况,所以上面的脚本就不适用了。

Get-MsolUser -MaxResults 25 | foreach {
  [PSCustomObject]@{ 'name' = $_.userprincipalname; 'license' = ($_.licenses | select -ExpandProperty AccountSkuId | Sort | Out-String).Trim() -replace "`n", ' & ' } | Export-Csv "C:Users
oot.csv" -Append -NoTypeInformation
} # | ft -Wrap -AutoSize

Get-MsolUser -MaxResults 25 | 
  select userprincipalname, 
         @{n='license';e={($_.licenses | select -ExpandProperty AccountSkuId | Sort | Out-String).Trim() -replace "`n", ' & ' }} | Export-Csv "C:Users
oot.csv" -Append -NoTypeInformation
         # | ft -AutoSize -Wrap
原文地址:https://www.cnblogs.com/IvanChen/p/5686970.html