计数SKU PR CompanyName在租户中具有多个公司名称-Powershell
(首先,对不起,如果我的英语到处都是一点点,仍然在学习)
,我希望有人对如何执行此操作有任何意见。目前,我在一家拥有Mutiple Companies的租户工作。我希望自动化如何获得SKU的所有公关公司,因为它们是单独收费的
。那有点完成工作。但是,它不计算并为我想要的东西提供最佳的输出。
$Report = [System.Collections.Generic.List[Object]]::new() # Create output file
$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)
}
}
$Report | Sort Companyname| Select Companyname, SKU, SKUName | Format-Table
#or replace Format-Table with Out-GridView for easier reading
正如我所说,这还可以。它并没有真正自动化我想做的事情。经过此操作后,我将不得不计算SKU的公关公司。从下面的输出。
Companyname SKU SKUName
----------- --- -------
company 01 18181a46-0d4e-45cd-891e-60aabd171b4e STANDARDPACK
company 01 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS
company 02 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS
company 02 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 02 06ebc4ee-1bb5-47dd-8120-11324bc54e06 SPE_E5
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD
我希望woud的输出是下面说明的内容:
Companyname SKU SKUName Amount
----------- --- ------- ------
company 01 18181a46-0d4e-45cd-891e-60aabd171b4e STANDARDPACK 1
company 01 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS 4
company 01 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 02 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS 5
company 02 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 02 06ebc4ee-1bb5-47dd-8120-11324bc54e06 SPE_E5 3
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD 2
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 6
我可能只是缺少超级明显的东西,我不确定。但是任何帮助都会非常好。
(first of all, sorry if my english is a little all over the place, still learning)
So i was hoping someone had any input on how to do this. Right now im working at a tenant that has mutiple companies in it. I was hoping to automate how I would get all the SKU's pr company, as they are billed separately etc.
right now i have the powershell-script below. that kinda gets the job done. However, its not counting and giving the best output possible for what i want.
$Report = [System.Collections.Generic.List[Object]]::new() # Create output file
$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)
}
}
$Report | Sort Companyname| Select Companyname, SKU, SKUName | Format-Table
#or replace Format-Table with Out-GridView for easier reading
and this is working ok as i said. its just not really automated for what i want to do. after i run this i would have to count up the SKU's pr company. from the output below.
Companyname SKU SKUName
----------- --- -------
company 01 18181a46-0d4e-45cd-891e-60aabd171b4e STANDARDPACK
company 01 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS
company 02 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS
company 02 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 02 06ebc4ee-1bb5-47dd-8120-11324bc54e06 SPE_E5
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD
the output i would like woud be something like im illustrating below:
Companyname SKU SKUName Amount
----------- --- ------- ------
company 01 18181a46-0d4e-45cd-891e-60aabd171b4e STANDARDPACK 1
company 01 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS 4
company 01 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 02 3b555118-da6a-4418-894f-7df1e2096870 O365_BUSINESS_ESSENTIALS 5
company 02 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 02 06ebc4ee-1bb5-47dd-8120-11324bc54e06 SPE_E5 3
company 03 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 2
company 04 a403ebcc-fae0-4ca2-8c8c-7a907fd6c235 POWER_BI_STANDARD 2
company 04 cbdc14ab-d96c-4c30-b9f4-6ada7cdc1d46 SPB 6
I might just be missing something super obv, im not sure. but any help would be very nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用
group-object
对公司进行组。默认情况下,这会使您计数Could you try using
Group-Object
to group by company. This fives you a count by default所以我终于设法做到了!我可能根本不是 做到这一点最多 1337 。但这现在正在起作用。它仍然不是完全自动化的。
因此,我还将发布一个版本,其中我将使用图形等。因为我以后使用此脚本在团队中使用机器人进行skus的日志更改。
但是,这是现在的脚本。 工作。
该脚本将为您列出表格中的所有可用公司名称。然后,您可以检查每个公司的SKUS 1 x 1。
输出将是一个表。
它还询问您是否要在第一次检查后检查另一家公司的广告。
正如我所说,我计划自动化这一点,以贯穿您合作的所有公司或其他公司。
我希望这可以帮助其他人同样。
So i finally managed to do it! I'm probably not at all doing this the most 1337 way. but this is now working. its still not fully automated.
so i will also be posting a version where i'll use graph etc. because im using this script later with a bot in teams to kinda log changes in SKUS.
However, here is the script as it is right now. working.
this script will list all available companynames in a table for you. and then you can check each company's SKUS 1 by 1.
the output will be a table.
it also ask if you want to check another company ad start over after your first check.
as i said, im planning to automate this to run through all companies you have partner in or something.
I hope this can help someone else out aswell.