
我想建立一個 One-Liner 來取得特定通訊組的註釋,並將其與通訊組的名稱和其他資訊一起輸出。我用谷歌搜尋了一下,發現不同的來源都有相同的解決方案。這是我找到的解決方案:
Get-DistributionGroup Head-of-Operations | Select-Object Name, GroupType, ManagedBy, @{Name="Notes";Expression={(Get-Group $_).Notes}}
這是此內容的來源之一:
https://richgski.blogspot.com/2012/03/powershell-get-exchange-distribution.html
但帶有註釋的行將始終保持空白,我不知道為什麼:
Name GroupType ManagedBy Notes
---- --------- --------- -----
Head-of-Ops Universal {}
當我單獨執行以下命令時:
Get-Group Head-of-Ops | Select-Object Notes
……它給了我正確的註釋作為輸出:
Notes
-----
Owner- Paul J.
我現在已經玩得更多了。以下程式碼可以完美運行:
$Result = Get-DistributionGroup Head-of-Operations
Get-Group $Result.Name | Select-Object Notes
輸出:
Notes
-----
Owner- Paul J.
但這仍然不起作用。它運行沒有任何錯誤,但註釋仍然是空白:
Get-DistributionGroup Head-of-Operations | Select-Object Name,GroupType,ManagedBy,@{Name="Notes";Expression={(Get-Group $_.Name | Select-Object Notes)}}
輸出:
Name GroupType ManagedBy Notes
---- --------- --------- -----
Head-of-Ops Universal {}
之後我在這裡找到了該主題的另一篇文章: https://www.oxfordsbsguy.com/2014/04/21/exchange-powershell-how-to-enumerate-distribution-lists-managers-and-members/#comment-4452
但仍使用以下命令:
Get-DistributionGroup Head-of-Ops | Select-Object Name,GroupType,ManagedBy,@{Expression={(Get-Group $_.Name).Notes};Label="Notes"}
我仍然得到相同的輸出,沒有任何註釋......
Name GroupType ManagedBy Notes
---- --------- --------- -----
Head-of-Ops Universal {}
我只是不明白:/
你們有人看到這個問題並可以指出我嗎?
親切的問候,
凱文範蒂爾
答案1
我現在已經使用 -verbose 參數運行此命令,我想我現在離解決方案又更近了一步。我認為在某些時候它只是缺少一個參數,但我不知道是哪個參數。
Get-DistributionGroup Head-of-Ops@h***.com -Verbose | Select-Object Name,GroupType,ManagedBy,@{Name="Notes";Expression={(Get-Group $_.Name).Notes}} -Verbose
VERBOSE: [16:04:28.885 GMT] Get-DistributionGroup : Active Directory session settings for 'Get-DistributionGroup' are: View Entire Forest: 'False', Default Scope: 'h***.de', Configuration Domain Controller: 'H***.h***.de',
Preferred Global Catalog: '***.h***.h***.de', Preferred Domain Controllers: '{ ****.h***.h***.de, H***.h***.de }'
VERBOSE: [16:04:28.916 GMT] Get-DistributionGroup : Runspace context: Executing user: h***.de/Companies/H***/D***/User/IT Service/****, Executing user organization: , Current organization: , RBAC-enabled: Enabled.
VERBOSE: [16:04:28.916 GMT] Get-DistributionGroup : Beginning processing &
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Current ScopeSet is: { Recipient Read Scope: {{, }}, Recipient Write Scopes: {{, }}, Configuration Read Scope: {{, }}, Configuration Write Scope(s): {{, }, }, Exclusive Recipient
Scope(s): {}, Exclusive Configuration Scope(s): {} }
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Resolved current organization: .
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Searching objects "Head-of-Ops@h***.com" of type "ADGroup" under the root "$null".
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Previous operation run on domain controller 'H***.h***.de'.
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Previous operation run on domain controller 'H***.h***.de'.
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Preparing to output objects. The maximum size of the result set is "1000".
VERBOSE: [16:04:28.947 GMT] Get-DistributionGroup : Ending processing &
Name GroupType ManagedBy Notes
---- --------- --------- -----
Head-of-Ops Universal {}
我認為下面這一行埋藏了問題:
VERBOSE: [16:04:28.932 GMT] Get-DistributionGroup : Searching objects "Head-of-Ops@h***.com" of type "ADGroup" under the root "$null".
有人知道它缺少什麼以及為什麼嗎?