我正在寻找从列表中转储与 UPN 匹配的 MsolAccountSku 许可证列表。
我正在寻找的内容如下:
[email protected] tenant:STANDARDPACK
[email protected] tenant:ENTERPRISEPACK
我对 PS 不是很在行,因此很难格式化输出并将其与 UPN 放在一起。
我目前拥有的:
$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
}
}
}
答案1
这比您要求的要复杂一些。
但我有一个旧功能可供您使用,它将用户的每个许可证映射到用户的 UPN,并显示显示名称。
该函数使用最常见的 SKU 名称的哈希表,并将其转换为人类可读的许可证版本。
如果您租户的 SKU 不在那里,只需将其添加到哈希表中即可。最终结果是一个漂亮的 .csv 文件,可以轻松导入 Excel,例如,您可以按许可证或用户进行排序,以了解谁使用了什么。
只需运行下面的代码来加载该函数,然后运行Get-LicenseUsage
。这将在您的 PS 当前所在的目录中创建一个 csv 文件(以租户命名)。
<#
.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 ";"
}
}
答案2
如果您只想通过显示 UPN 及其关联的 SKU 来获取输出。您只需调整原始脚本即可。除非您还打算显示服务计划,否则您必须合并 ServiceStatus 部分
以下是一个编辑,仅显示 UPN 和 SKU
$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 }
}
}