gpt4 book ai didi

azure - 组合和匹配 Get-AzureADUser、Get-AzureADSubscribedSku 、 Get-AzureADUserManager 的输出

转载 作者:行者123 更新时间:2023-12-03 06:41:23 29 4
gpt4 key购买 nike

问题和我现在遇到的问题

<小时/>

脚本

顺便说一句,评论是挪威语的,如果它们看起来很奇怪哈哈

Connect-AzureAD

#variabel
$Users = Get-AzureADUser -All:$true | where-object { $null -ne $_.AssignedLicenses.SkuId } | Sort-Object CompanyName, UserPrincipalName| Select-Object -Property CompanyName, DisplayName, UserPrincipalName, Department, Mobile, TelephoneNumber

#formatting
$userlistTable = $Users | Format-Table
$userlistHTML = $Users | ConvertTo-Html

#outputs
$userlistHTML > out.html # ut som HTML
$userlistTable > out.txt # ut som Tabell i .txt
$userlistTable # ut som Tabell i terminal

我现在的输出:

CompanyName        DisplayName        UserPrincipalName          Department        Mobile          TelephoneNumber
----------- ----------- ----------------- ---------- ------ ---------------
Company inc Usser Name usernam<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="caaf8abdafa8b9a3beafe4a9a5a7" rel="noreferrer noopener nofollow">[email protected]</a> Callsenter 12345678 87654321

我想要什么。是一个表,其中包含 $Users 输出中的所有信息以包含用户“SkuPartNumber”。
通过运行命令 Get-AzureADSubscribedSku | 获取的字段选择-Property SkuPartNumber


我还想获得通过运行 Get-AzureADUserManager 获得的用户“经理”。

最后一个命令使用用户对象 ID 来查找他们的经理。老实说,我非常不知道如何将这些命令组合到一张表中。

<小时/>

这并不是现在的世界末日。我可以只有多个表,但必须手动交叉引用这些表需要一些时间。

说实话,我真的不确定为什么这些东西被分成不同的命令。我知道许可证是通过 365 而不是 azure 的。但似乎有点倒退,我无法从显示所有用户信息的命令中看到许可证。当 powershell 中的用户类别实际上显示 sku ID 时。通过运行命令,它被隐藏在 AssignedLicenses 中:

Get-AzureADUser | where-object -property UserPrincipalName -eq "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1d4dcd0d8ddd9d4c3d4f1d5dedcd0d8df9fd2dedc" rel="noreferrer noopener nofollow">[email protected]</a>" | FL

这将为您提供以下信息:

AssignedLicenses               : {class AssignedLicense {
DisabledPlans: System.Collections.Generic.List`1[System.String]
SkuId: 3b555118-da6a-4418-894f-7df1e2096870
}

结论

我知道这是一篇很长的文章。如果你做到了这一步,我很抱歉。对此的任何帮助都会很棒。这可能非常容易做到,但我距离 powershell 专家还很远。再次感谢您的阅读以及任何帮助。

最佳答案

您可以使用计算属性向选定对象添加其他属性,例如 Select @{label='name';expression={foo}}

$Users = Get-AzureADUser -All:$true

$Users | Where-Object { $_.AssignedLicenses.SkuId } |
Select-Object -Property UserPrincipalName, ## other properties here...
@{l='ManagerUPN';e={($_ | Get-AzureADUserManager).UserPrincipalName}},
@{l='AssignedSKUs';e={$_.AssignedLicenses.SkuId -join ';'}}


UserPrincipalName ManagerUPN AssignedSKUs
----------------- ---------- ------------
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcaccdacdffdbd0d2ded6d191dcd0d2" rel="noreferrer noopener nofollow">[email protected]</a> <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="58353936393f3d2a183c3735393136763b3735" rel="noreferrer noopener nofollow">[email protected]</a> 00000000-0000-0000-0000-000000000000;11111111-1111-1111-1111-111111111111

为每个用户运行 Get-AzureADUserManager 可能会很慢,但这就是 Azure 存储关系的方式。

当您有很多用户时,首先获取管理员用户可能会稍微快一些,然后使用 Get-AzureADUserDirectReport -all $true 展开所有在一次调用中directreportsMicrosoft.Graph.Users 模块也更加轻量级

关于azure - 组合和匹配 Get-AzureADUser、Get-AzureADSubscribedSku 、 Get-AzureADUserManager 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74477562/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com