首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从列表中转储MsolAccountSku和UPN

从列表中转储MsolAccountSku和UPN
EN

Server Fault用户
提问于 2019-02-04 22:42:29
回答 2查看 398关注 0票数 1

我希望从列表中转储与UPN相匹配的MsolAccountSku许可证列表。

我要找的是以下几点:

代码语言:javascript
复制
user@domain.com tenant:STANDARDPACK
user2@domain.com tenant:ENTERPRISEPACK

我不是很好的PS,所以有一个困难的时间格式化输出,并把它与UPN。

到目前为止我所拥有的是:

代码语言:javascript
复制
$readFile = `
  Get-Content "C:\temp\changelicense.csv"

  foreach($upn in $readFile){

$licensedetails = (Get-MsolUser -UserPrincipalName `
  $upn).Licenses
$licensedetails.AccountSKUId;

if ($licensedetails.Count -gt 0){
  foreach ($i in $licensedetails){
    $i.ServiceStatus 

  }
}
}
EN

回答 2

Server Fault用户

发布于 2019-02-05 13:38:29

这比你要求的要复杂一些。但我有一个旧函数,您可以使用它将用户的每个许可证映射到用户的UPN,并显示显示名称。

该函数使用最常见的SKU名称的哈希表,并将它们转换为许可的人类可读的版本。

如果租户的SKU不在那里,只需将其添加到Hash表中即可。最终的结果是一个很好的.csv文件,可以很容易地导入到Excel中,这样您就可以对许可证或用户进行排序,从而了解谁使用了什么。

只需运行下面的代码来加载函数,然后运行Get-LicenseUsage。这将在PS当前所在的目录(以租户的名字命名)中创建一个csv文件。

代码语言:javascript
复制
<#
.SYNOPSIS
    Creates a list showing which users has assigned which licenses.

.DESCRIPTION
    Creates a list of all licenses and which user the license is assigned to.
    The list is then output to a csv file, the file is output in the directory the script is run in.
    The filename is automatically created and uses the company name of the Office 365 Tenant.

.EXAMPLE
    Get-LicenseUsage

.NOTES
    Author: Henrik Stanley Mortensen

#>
Function Get-LicenseUsage()
{
    process  {
        $SkuPartFriendlyName = @{
            ########### Enterprise SKU's################
            "STANDARDPACK" = "Enterprise E1"
            "ENTERPRISEPACK" = "Enterprise E3"
            "ENTERPRISEPACKWSCAL" = "Enterprise E4"
            "ENTERPRISEWITHSCAL" = "Enterprise E4"
            "ENTERPRISEPREMIUM_NOPSTNCONF" = "Enterprise E5 w/o PSTN Conferencing"
            "ENTERPRISEPREMIUM " = "Enterprise E5"
            "EMS" = "Enterprise Mobility Pack"
            "AAD_BASIC" = "Azure Active Directory Basic"
            "AAD_PREMIUM" = "Azure Active Directory Premium"
            ############ Business SKU's#################
            "EXCHANGESTANDARD" = "Exchange Online Plan 1"
            "O365_BUSINESS_ESSENTIALS" = "Business Essentials"
            "O365_BUSINESS" = "Business"
            "O365_BUSINESS_PREMIUM" = "Business Premium"
            ############ Standalone Products############
            "POWER_BI_STANDARD" = "Power BI"
            "FLOW_FREE" = "Flow"
            "POWER_BI_PRO" = "Power BI Pro"
            "POWER_BI_STANDALONE" = "Microsoft Power BI for Office 365"
            "PROJECTESSENTIALS" = "Project Online"
            "PROJECTPROFESSIONAL" = "Project Online Professional"
            "PROJECTONLINE_PLAN_1" = "Project Online"
            "PROJECTCLIENT" = "Project Pro for Office 365"
            "RIGHTSMANAGEMENT_ADHOC" = "Rights Management Adhoc"
            "VISIOCLIENT" = "Visio Pro for Office 365"
            "INTUNE_A" = "Intune A Direct"
            "CRMIUR" = "Dynamics CRM URI"
            "MCOMEETADV" = "Skype for Business PSTN Conferencing"
        }

        $lines = @()
        $array= New-Object System.Collections.ArrayList

        foreach($msolUser in (Get-MSOLUser -All | Where-Object {$_.isLicensed -eq $true}))
        {
            $i = 0
            $licenses = New-Object System.Collections.ArrayList
            foreach($SKU in $msolUser.licenses.AccountSku.SkuPartNumber) {
                #Runs the SkuPartNumber through the Friendly Name List to translate the license
                $licenses = $SkuPartFriendlyName.Item($msolUser.licenses[$i].AccountSku.SkuPartNumber)

                #Creates an object with information for the user license
                $lines = @{
                            "Display Name" = "$($msolUser.DisplayName)";
                            "Licenses" = "$licenses";
                            "Login" = "$($msolUser.UserPrincipalName)";
                            }

                $userInfo = New-Object -TypeName psobject -Property $lines

                #Adds the object to an array used for export
                $array.Add($UserInfo)
                $i++
            }
        }
        #Exports the array to a csv file
        $filename = (Get-MsolCompanyInformation).DisplayName + ' License Overview.csv'
        $filename = $filename -replace "/", "."
        $array | Select-Object Login, 'Display Name', Licenses | Export-CSV $filename -Encoding UTF8 -NoTypeInformation -Delimiter ";"
    }
}
票数 0
EN

Server Fault用户

发布于 2019-02-07 17:01:56

如果您只是通过显示UPN和它们的关联SKU来寻找输出。你可以修改原始脚本。除非您也打算显示服务计划,否则您必须合并ServiceStatus部分

下面是一个编辑,用于只显示UPN和SKU

代码语言:javascript
复制
$readFile = Get-Content "C:\temp\changelicense.csv"

foreach($upn in $readFile){

$licensedetails = (Get-MsolUser -UserPrincipalName $upn).Licenses

if ($licensedetails.Count -gt 0){
    foreach ($i in $licensedetails){
        $upn + " " + $licensedetails.accountSKUId }
  }
}
票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/952298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档