负责采购的同事需要知道目前公司使用了多少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
时间: 2024-10-13 16:38:02