问题
你好!我有一个问题,我也在这里再描述一下。但问题是,此脚本在同一行中添加"Count“列的对应值的次数与"Count”中的值相同。
示例:
Count Name SKUName
----- ---- -------
4 f8a1db68-be16-40ed-86d5-cb42ce701560 Power Bi Pro, Power Bi Pro, Power Bi Pro, Power Bi Pro可能听起来很混乱,因为我的英语不是最好的。但我进一步说明了这一点。
这是函数(整个脚本也更向下一点)
cls
#List of company names in the tenant
$Companies = $Report | Select-Object Companyname -Unique
#horrible improvised "for" loop that goes through the list of companynames
$counter = 0 #starting at pos [0]
foreach ($company in $Companies) {
#prints the current companyname
$Companies.companyname[$counter]
#formatting the table for the current companyname[i] where it shows count, name, and SKUName
$Report | Where-Object Companyname -like $Companies.companyname[$counter] | Group-Object -Property SKU | Select-Object Count, Name, @{Name = 'SKUName' ; expression = { ($LicenseLookup[$_.Group.SKUName]) -join ', ' } } | Format-Table
#then moves down 1 pos in the current companyname[i]
$counter = $counter + 1
Write-Host "--------------------------------------------------------------------------------------------"
}
我想这条线可以调整一下。
$Report | Where-Object Companyname -like $Companies.companyname[$counter] | Group-Object -Property SKU | Select-Object Count, Name, @{Name = 'SKUName' ; expression = { ($LicenseLookup[$_.Group.SKUName]) -join ', ' } } | Format-Table在任何情况下它都是创建输出的行。这里的任何帮助都会很棒的。
正如我所说的,下面是我想要得到的问题和规则的说明。还有我的剧本。该脚本将支持您使用m365租户上的全局管理帐户登录。然后,它将打印一张表格,上面有所有SKUS/许可证上的信息,供租户内的每一家公司使用。
我的剧本
cls
Connect-AzureAD
$Report = [System.Collections.Generic.List[Object]]::new()
$Skus = Get-AzureADSubscribedSku | Select Sku*, ConsumedUnits
ForEach ($Sku in $Skus) {
Write-Host "Processing license holders for" $Sku.SkuPartNumber
$SkuUsers = Get-AzureADUser -All $True | ? { $_.AssignedLicenses -Match $Sku.SkuId }
ForEach ($User in $SkuUsers) {
$ReportLine = [PSCustomObject] @{
User = $User.DisplayName
UPN = $User.UserPrincipalName
Companyname = $User.Companyname
Country = $User.Country
SKU = $Sku.SkuId
SKUName = $Sku.SkuPartNumber
}
$Report.Add($ReportLine)
}
}
$LicenseLookup = @{
'SPZA_IW' = 'App Connect Iw'
'AAD_BASIC' = 'Azure Active Directory Basic'
'AAD_PREMIUM' = 'Azure Active Directory Premium P1'
'AAD_PREMIUM_P2' = 'Azure Active Directory Premium P2'
'RIGHTSMANAGEMENT' = 'Azure Information Protection Plan 1'
'MCOCAP' = 'Common Area Phone'
'MCOPSTNC' = 'Communications Credits'
'DYN365_ENTERPRISE_PLAN1' = 'Dynamics 365 Customer Engagement Plan Enterprise Edition'
'DYN365_ENTERPRISE_CUSTOMER_SERVICE' = 'Dynamics 365 For Customer Service Enterprise Edition'
'DYN365_FINANCIALS_BUSINESS_SKU' = 'Dynamics 365 For Financials Business Edition'
'DYN365_ENTERPRISE_SALES_CUSTOMERSERVICE' = 'Dynamics 365 For Sales And Customer Service Enterprise Edition'
'DYN365_ENTERPRISE_SALES' = 'Dynamics 365 For Sales Enterprise Edition'
'DYN365_ENTERPRISE_TEAM_MEMBERS' = 'Dynamics 365 For Team Members Enterprise Edition'
'DYN365_TEAM_MEMBERS' = 'Dynamics 365 Team Members'
'Dynamics_365_for_Operations' = 'Dynamics 365 Unf Ops Plan Ent Edition'
'EMS' = 'Enterprise Mobility + Security E3'
'EMSPREMIUM' = 'Enterprise Mobility + Security E5'
'EXCHANGESTANDARD' = 'Exchange Online (Plan 1)'
'EXCHANGEENTERPRISE' = 'Exchange Online (Plan 2)'
'EXCHANGEARCHIVE_ADDON' = 'Exchange Online Archiving For Exchange Online'
'EXCHANGEARCHIVE' = 'Exchange Online Archiving For Exchange Server'
'EXCHANGEESSENTIALS' = 'Exchange Online Essentials'
'EXCHANGE_S_ESSENTIALS' = 'Exchange Online Essentials'
'EXCHANGEDESKLESS' = 'Exchange Online Kiosk'
'EXCHANGETELCO' = 'Exchange Online Pop'
'INTUNE_A' = 'Intune'
'M365EDU_A1' = 'Microsoft 365 A1'
'M365EDU_A3_FACULTY' = 'Microsoft 365 A3 For Faculty'
'M365EDU_A3_STUDENT' = 'Microsoft 365 A3 For Students'
'M365EDU_A5_FACULTY' = 'Microsoft 365 A5 For Faculty'
'M365EDU_A5_STUDENT' = 'Microsoft 365 A5 For Students'
'O365_BUSINESS' = 'Microsoft 365 Apps For Business'
'SMB_BUSINESS' = 'Microsoft 365 Apps For Business'
'OFFICESUBSCRIPTION' = 'Microsoft 365 Apps For Enterprise'
'MCOMEETADV' = 'Microsoft 365 Audio Conferencing'
'MCOMEETADV_GOC' = 'Microsoft 365 Audio Conferencing For Gcc'
'O365_BUSINESS_ESSENTIALS' = 'Microsoft 365 Business Basic'
'SMB_BUSINESS_ESSENTIALS' = 'Microsoft 365 Business Basic'
'SPB' = 'Microsoft 365 Business Premium'
'O365_BUSINESS_PREMIUM' = 'Microsoft 365 Business Standard'
'SMB_BUSINESS_PREMIUM' = 'Microsoft 365 Business Standard'
'MCOPSTN_5' = 'Microsoft 365 Domestic Calling Plan (120 Minutes)'
'SPE_E3' = 'Microsoft 365 E3'
'SPE_E3_USGOV_DOD' = 'Microsoft 365 E3_Usgov_Dod'
'SPE_E3_USGOV_GCCHIGH' = 'Microsoft 365 E3_Usgov_Gcchigh'
'SPE_E5' = 'Microsoft 365 E5'
'INFORMATION_PROTECTION_COMPLIANCE' = 'Microsoft 365 E5 Compliance'
'IDENTITY_THREAT_PROTECTION' = 'Microsoft 365 E5 Security'
'IDENTITY_THREAT_PROTECTION_FOR_EMS_E5' = 'Microsoft 365 E5 Security For Ems E5'
'M365_F1' = 'Microsoft 365 F1'
'SPE_F1' = 'Microsoft 365 F3'
'M365_G3_GOV' = 'Microsoft 365 Gcc G3'
'MCOEV' = 'Microsoft 365 Phone System'
'PHONESYSTEM_VIRTUALUSER' = 'Microsoft 365 Phone System - Virtual User'
'MCOEV_DOD' = 'Microsoft 365 Phone System For Dod'
'MCOEV_FACULTY' = 'Microsoft 365 Phone System For Faculty'
'MCOEV_GOV' = 'Microsoft 365 Phone System For Gcc'
'MCOEV_GCCHIGH' = 'Microsoft 365 Phone System For Gcchigh'
'MCOEVSMB_1' = 'Microsoft 365 Phone System For Small And Medium Business'
'MCOEV_STUDENT' = 'Microsoft 365 Phone System For Students'
'MCOEV_TELSTRA' = 'Microsoft 365 Phone System For Telstra'
'MCOEV_USGOV_DOD' = 'Microsoft 365 Phone System_Usgov_Dod'
'MCOEV_USGOV_GCCHIGH' = 'Microsoft 365 Phone System_Usgov_Gcchigh'
'WIN_DEF_ATP' = 'Microsoft Defender Advanced Threat Protection'
'CRMSTANDARD' = 'Microsoft Dynamics Crm Online'
'CRMPLAN2' = 'Microsoft Dynamics Crm Online Basic'
'FLOW_FREE' = 'Microsoft Flow Free'
'INTUNE_A_D_GOV' = 'Microsoft Intune Device For Government'
'POWERAPPS_VIRAL' = 'Microsoft Power Apps Plan 2 Trial'
'TEAMS_FREE' = 'Microsoft Team (Free)'
'TEAMS_EXPLORATORY' = 'Microsoft Teams Exploratory'
'IT_ACADEMY_AD' = 'Ms Imagine Academy'
'ENTERPRISEPREMIUM_FACULTY' = 'Office 365 A5 For Faculty'
'ENTERPRISEPREMIUM_STUDENT' = 'Office 365 A5 For Students'
'EQUIVIO_ANALYTICS' = 'Office 365 Advanced Compliance'
'ATP_ENTERPRISE' = 'Microsoft Defender for Office 365 (Plan 1)'
'STANDARDPACK' = 'Office 365 E1'
'STANDARDWOFFPACK' = 'Office 365 E2'
'ENTERPRISEPACK' = 'Office 365 E3'
'DEVELOPERPACK' = 'Office 365 E3 Developer'
'ENTERPRISEPACK_USGOV_DOD' = 'Office 365 E3_Usgov_Dod'
'ENTERPRISEPACK_USGOV_GCCHIGH' = 'Office 365 E3_Usgov_Gcchigh'
'ENTERPRISEWITHSCAL' = 'Office 365 E4'
'ENTERPRISEPREMIUM' = 'Office 365 E5'
'ENTERPRISEPREMIUM_NOPSTNCONF' = 'Office 365 E5 Without Audio Conferencing'
'DESKLESSPACK' = 'Office 365 F3'
'ENTERPRISEPACK_GOV' = 'Office 365 Gcc G3'
'MIDSIZEPACK' = 'Office 365 Midsize Business'
'LITEPACK' = 'Office 365 Small Business'
'LITEPACK_P2' = 'Office 365 Small Business Premium'
'WACONEDRIVESTANDARD' = 'Onedrive For Business (Plan 1)'
'WACONEDRIVEENTERPRISE' = 'Onedrive For Business (Plan 2)'
'POWER_BI_STANDARD' = 'Power Bi (Free)'
'POWER_BI_ADDON' = 'Power Bi For Office 365 Add-On'
'POWER_BI_PRO' = 'Power Bi Pro'
'PROJECTCLIENT' = 'Project For Office 365'
'PROJECTESSENTIALS' = 'Project Online Essentials'
'PROJECTPREMIUM' = 'Project Online Premium'
'PROJECTONLINE_PLAN_1' = 'Project Online Premium Without Project Client'
'PROJECTPROFESSIONAL' = 'Microsoft Project Plan 3'
'PROJECTONLINE_PLAN_2' = 'Project Online With Project For Office 365'
'SHAREPOINTSTANDARD' = 'Sharepoint Online (Plan 1)'
'SHAREPOINTENTERPRISE' = 'Sharepoint Online (Plan 2)'
'MCOIMP' = 'Skype For Business Online (Plan 1)'
'MCOSTANDARD' = 'Skype For Business Online (Plan 2)'
'MCOPSTN2' = 'Skype For Business Pstn Domestic And International Calling'
'MCOPSTN1' = 'Skype For Business Pstn Domestic Calling'
'MCOPSTN5' = 'Skype For Business Pstn Domestic Calling (120 Minutes)'
'MCOPSTNEAU2' = 'Telstra Calling For O365'
'TOPIC_EXPERIENCES' = 'Topic Experiences'
'VISIOONLINE_PLAN1' = 'Visio Online Plan 1'
'VISIOCLIENT' = 'Visio Online Plan 2'
'VISIOCLIENT_GOV' = 'Visio Plan 2 For Gov'
'WIN10_PRO_ENT_SUB' = 'Windows 10 Enterprise E3'
'WIN10_VDA_E3' = 'Windows 10 Enterprise E3'
'WIN10_VDA_E5' = 'Windows 10 Enterprise E5'
'WINDOWS_STORE' = 'Windows Store For Business'
'RMSBASIC' = 'Azure Information Protection Basic'
'UNIVERSAL_PRINT_M365' = 'Universal Print'
'RIGHTSMANAGEMENT_ADHOC' = 'Rights Management Service Basic Content Protection'
'SKU_Dynamics_365_for_HCM_Trial' = 'Dynamics 365 for Talent'
'PROJECT_P1' = 'Project Plan 1'
'PROJECT_PLAN1_DEPT' = 'Project Plan 1 (Self Service)'
'SHAREPOINTSTORAGE' = 'Microsoft Office 365 Extra File Storage'
'NONPROFIT_PORTAL' = 'Non Profit Portal'
'MDE_SMB' = 'Microsoft Defender for Endpoint (Business Premium)'
}
cls
#List of company names in the tenant
$Companies = $Report | Select-Object Companyname -Unique
#horrible improvised "for" loop that goes through the list of companynames
$counter = 0 #starting at pos [0]
foreach ($company in $Companies) {
#prints the current companyname
$Companies.companyname[$counter]
#formatting the table for the current companyname[i] where it shows count, name, and SKUName
$Report | Where-Object Companyname -like $Companies.companyname[$counter] | Group-Object -Property SKU | Select-Object Count, Name, @{Name = 'SKUName' ; expression = { ($LicenseLookup[$_.Group.SKUName]) -join ', ' } } | Format-Table
#then moves down 1 pos in the current companyname[i]
$counter = $counter + 1
Write-Host "--------------------------------------------------------------------------------------------"
}产出。
下面是我的脚本中的当前输出。正如你所看到的。公司拥有的每一个许可证。它在同一行中多次写入该许可证的名称。
--------------------------------------------------------------------------------------------
Company 1
Count Name SKUName
----- ---- -------
4 f8a1db68-be16-40ed-86d5-cb42ce701560 Power Bi Pro, Power Bi Pro, Power Bi Pro, Power Bi Pro
15 f30db892-07e9-47e9-837c-80727f46fd3d Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free, M...
2 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 Microsoft 365 Business Premium, Microsoft 365 Business Premium
29 4b9405b0-7788-4568-add1-99614e613b69 Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange...
44 f245ecc8-75af-4f8e-b61f-27d8114de5f3 Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business St...
6 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 Power Bi (Free), Power Bi (Free), Power Bi (Free), Power Bi (Free), Power Bi (Free), Power Bi (Free)
3 710779e8-3d4a-4c88-adb9-386c958d1fdf Microsoft Teams Exploratory, Microsoft Teams Exploratory, Microsoft Teams Exploratory
59 3b555118-da6a-4418-894f-7df1e2096870 Microsoft 365 Business Basic, Microsoft 365 Business Basic, Microsoft 365 Business Basic, Microsoft 365 Business Basic, Microsoft 365 Business Basic, Microsoft 365 Business Basic, Microsoft ...
10 1e1a282c-9c54-43a2-9310-98ef728faace Dynamics 365 For Sales Enterprise Edition, Dynamics 365 For Sales Enterprise Edition, Dynamics 365 For Sales Enterprise Edition, Dynamics 365 For Sales Enterprise Edition, Dynamics 365 For S...
--------------------------------------------------------------------------------------------
Company 2
Count Name SKUName
----- ---- -------
3 f30db892-07e9-47e9-837c-80727f46fd3d Microsoft Flow Free, Microsoft Flow Free, Microsoft Flow Free
36 4b9405b0-7788-4568-add1-99614e613b69 Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange Online (Plan 1), Exchange...
12 f245ecc8-75af-4f8e-b61f-27d8114de5f3 Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business Standard, Microsoft 365 Business St...
2 710779e8-3d4a-4c88-adb9-386c958d1fdf Microsoft Teams Exploratory, Microsoft Teams Exploratory
--------------------------------------------------------------------------------------------
我希望输出的结果是:
太乱了。所以我希望它能像下面这样。
--------------------------------------------------------------------------------------------
Company 1
Count Name SKUName
----- ---- -------
4 f8a1db68-be16-40ed-86d5-cb42ce701560 Power Bi Pro, Power Bi Pro
15 f30db892-07e9-47e9-837c-80727f46fd3d Microsoft Flow Free
2 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 Microsoft 365 Business Premium
29 4b9405b0-7788-4568-add1-99614e613b69 Exchange Online (Plan 1)
44 f245ecc8-75af-4f8e-b61f-27d8114de5f3 Microsoft 365 Business Standard
6 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 Power Bi (Free)
3 710779e8-3d4a-4c88-adb9-386c958d1fdf Microsoft Teams Exploratory
59 3b555118-da6a-4418-894f-7df1e2096870 Microsoft 365 Business Basic
10 1e1a282c-9c54-43a2-9310-98ef728faace Dynamics 365 For Sales Enterprise Edition
-------------------------------------------------------------------------------------
Company 2
Count Name SKUName
----- ---- -------
3 f30db892-07e9-47e9-837c-80727f46fd3d Microsoft Flow Free
36 4b9405b0-7788-4568-add1-99614e613b69 Exchange Online (Plan 1)
12 f245ecc8-75af-4f8e-b61f-27d8114de5f3 Microsoft 365 Business Standard
2 710779e8-3d4a-4c88-adb9-386c958d1fdf Microsoft Teams Exploratory
-------------------------------------------------------------------------------------发布于 2022-09-07 06:45:51
正如@MathiasR.Jesse在他的评论中所说的。修复方法是将$Report更改为使用以下内容:
($LicenseLookup[$_.Group.SKUName] | Sort-Object -Unique) -join ', '
功能更新如下。
cls
#List of company names in the tenant
$Companies = $Report | Select-Object Companyname -Unique
#horrible improvised "for" loop that goes through the list of companynames
$counter = 0 #starting at pos [0]
foreach ($company in $Companies) {
#prints the current companyname
$Companies.companyname[$counter]
#formatting the table for the current companyname[i] where it shows count, name, and SKUName
$Report | Where-Object Companyname -like $Companies.companyname[$counter] | Group-Object -Property SKU | Select-Object Count, Name, @{Name = 'SKU Name' ; expression = { ($LicenseLookup[$_.Group.SKUName] | Sort-Object -Unique) -join ', ' } } | Format-Table
#then moves down 1 pos in the current companyname[i]
$counter = $counter + 1
Write-Host "--------------------------------------------------------------------------------------------"
}仅$Report表:
$Report | Where-Object Companyname -like $Companies.companyname[$counter] | Group-Object -Property SKU | Select-Object Count, Name, @{Name = 'SKU Name' ; expression = { ($LicenseLookup[$_.Group.SKUName] | Sort-Object -Unique) -join ', ' } } | Format-Tablehttps://stackoverflow.com/questions/73623389
复制相似问题