我想构建一个单行程序来获取特定通讯组的注释,并将其与通讯组的名称和其他信息一起输出。
我在 Google 上搜索过,发现不同的来源提供相同的解决方案。这是我找到的解决方案之一:
https://richgski.blogspot.com/2012/03/powershell-get-exchange-distribution.html
Get-DistributionGroup Head-of-Operations | Select-Object Name, GroupType, ManagedBy, @{Name="Notes";Expression={(Get-Group $_).Notes}}
但是,带有注释的行始终保持空白,我不知道为什么:
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 {}
我就是不明白 :/
你们中有人看到了这个问题并且可以指出我吗?
亲切的问候,
凯文·范蒂尔
附言:我现在已经使用 -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".
有人知道它缺少了什么以及为什么吗?
答案1
当创建计算属性时,Select-Object
您需要
- 表达式,可以缩写为 E/e
- 一个名字或者标签,它们是同义词,也可以简化为第一个字母。
从您的问题来看,不清楚是否Get-DistributionGroup Head-of-Operations
返回单个还是多个对象?
也Head-of-Operations
和 一样吗Head-of-Ops
?
通过 Select-Object 添加属性的另一种方法是创建[PSCustomObject]
foreach($HeadOP in Get-DistributionGroup Head-of-Operations){
[PSCustomObject]@{
Name = $HeadOp.Name
GroupType = $HeadOp.GroupType
ManagedBy = $HeadOp.ManagedBy
Notes = (Get-Group $HeadOp.Name | Select-Object Notes)
}
}
最终你需要-ExpandProperty Notes
Notes = (Get-Group $HeadOp.Name | Select-Object -ExpandProperty Notes)
或更短
Notes = (Get-Group $HeadOp.Name).Notes
答案2
您使用哪个版本的 Exchange?
我测试了“ ”,它在我的 Exchange 2010 和 2013 实验室中都运行正常。Get-DistributionGroup "[email protected]" | Select-Object Name, GroupType, ManagedBy, @{Name="Notes";Expression={(Get-Group $_).Notes}} | ft -AutoSize
根据您的描述,“ManagedBy”属性为空也很奇怪。我不确定您是如何创建此 DG 的,但我认为您可以尝试使用新的测试 DG,如果脚本有效,那么我认为您可以检查此 DG 的配置,或者只是重建它。