在Powershell中显示M365许可证总数

问题描述 投票:0回答:1

我想创建一个 Powershell 脚本来显示购买的 M365 许可证的总数和分配的数量。但是,cmdlet“Get-MgSubscribedSKU”中不存在输出“ActiveUnits”。我需要哪个输出才能获得购买的许可证总数?

这是我的代码片段:

Get-MgSubscribedSKU | ForEach-Object {
    [PSCustomObject]@{
        License  = switch -Regex ($_.SkuPartNumber) {
            "VISIOCLIENT"                                           { "Visio Plan 2" }
        }
    Designation             = $_.SkuPartNumber
    LicenseID               = $_.SkuId
    NumberTotal             = $_.ActiveUnits
    NumberUsed              = $_.ConsumedUnits
    } 
} | sort License | Format-Table

感谢您提前的答复。

azure powershell azure-powershell
1个回答
0
投票

要获取已购买许可证的总数,您需要将脚本修改为以下内容:

Get-MgSubscribedSKU -All | Select-Object SkuPartNumber, SkuId, @{Name = "ActiveUnits"; Expression = { ($_.PrepaidUnits).Enabled } }, ConsumedUnits |
    ForEach-Object {
        [PSCustomObject]@{
        License  = switch -Regex ($_.SkuPartNumber) {
            "VISIOCLIENT"                                           { "Visio Plan 2" }
        }
    Designation             = $_.SkuPartNumber
    LicenseID               = $_.SkuId
    NumberTotal             = $_.ActiveUnits
    NumberUsed              = $_.ConsumedUnits
    } 
} | sort License | Format-Table

在我的 Azure AD 租户中,我拥有 许可证,详细信息如下:

enter image description here

当我通过进行一些更改来运行 PowerShell 脚本时,我成功地得到了response,如下所示:

Get-MgSubscribedSKU -All | Select-Object SkuPartNumber, SkuId, @{Name = "ActiveUnits"; Expression = { ($_.PrepaidUnits).Enabled } }, ConsumedUnits |
    ForEach-Object {
        [PSCustomObject]@{
            License       = switch -Regex ($_.SkuPartNumber) {
                "EMSPREMIUM" { "Enterprise Mobility + Security E5" }
                "ENTERPRISEPREMIUM" { "Office 365 E5" }
                "ENTERPRISEPACK" { "Office 365 G3 GCC" }
                "DESKLESSPACK" { "Office 365 F3" }
                "FLOW_FREE" { "Microsoft Power Automate Free" }
                "Win10_VDA_E3" { "WINDOWS 10/11 ENTERPRISE E3" }
                "INFORMATION_PROTECTION_COMPLIANCE" { "Microsoft 365 E5 Compliance" }
            }
            Designation   = $_.SkuPartNumber
            LicenseID     = $_.SkuId
            NumberTotal   = $_.ActiveUnits
            NumberUsed    = $_.ConsumedUnits
        }
    } | Sort-Object License | Format-Table

回复:

enter image description here

参考: 如何使用 Microsoft Graph 的 cmd 获取活动许可证数量 - Microsoft 问答,作者:Tyler Montney

© www.soinside.com 2019 - 2024. All rights reserved.