簡體   English   中英

Powershell-輸出管道中對象數組的各個成員

[英]Powershell - Output individual members of an array of objects in a pipeline

我不確定標題是否正確。 而且我知道這很容易回答,並且可能遍布整個互聯網。 但是,我需要你的幫助。

如果我運行一個powershell命令返回多個對象,並且每個對象都有它自己的成員,而其中一個成員是另一個包含多個對象的列表,那么將其干凈地輸出到屏幕的最有效方法是什么?

例如,請參閱以下命令以查詢用戶在Office 365中選擇的MFA身份驗證方法:

Get-MsolUser -All | where {$_.StrongAuthenticationMethods -ne $null} | Select-Object -Property UserPrincipalName, StrongAuthenticationMethods

輸出為:

UserPrincipalName                  StrongAuthenticationMethods
-----------------                  ---------------------------
user1@domain.com       {Microsoft.Online.Administration.StrongAuthenticationMethod, Microsoft.Online.Adm...
user2@domain.com       {Microsoft.Online.Administration.StrongAuthenticationMethod, Microsoft.Online.Adm...
user3@domain.com       {Microsoft.Online.Administration.StrongAuthenticationMethod, Microsoft.Online.Adm...

我想在一行代碼中列出UserPrincipalName,后跟每個StrongAuthenticationMethods對象的MethodType成員的值。

放輕松,我知道這有一個明顯的答案。

一種方法是展開內部集合,並為外部集合中的每個對象輸出一個。 示例(未經測試):

Get-MsolUser -All | Where-Object { $_.StrongAuthenticationMethods } | ForEach-Object {
  $upn = $_.UserPrincipalName
  $_.StrongAuthenticationMethods | ForEach-Object {
    [PSCustomObject] @{
      "UserPrincpalName"            = $upn
      "StrongAuthenticationMethods" = $_
    }
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM