【发布时间】:2016-08-12 18:42:22
【问题描述】:
我正在使用 Powershell 来显示所有组策略以及它们所链接的内容。这需要 GroupPolicy 模块(Import-Module GroupPolicy)和以下脚本(感谢 Mike Frobbins)完全满足我的需要,但输出以以下格式显示:
“GPOName”、“LinksTo”、“已启用”
"默认组策略","Servers,Computers,Texas","true,true,true"
我需要它看起来像这样:
“GPOName”、“LinksTo”、“已启用”
"默认组策略","服务器","true"
"默认组策略","计算机","true"
"默认组策略","Texas","true"
任何帮助将不胜感激。我一直试图让它工作 2 天,但我无法弄清楚。我发现其他文章涵盖了该主题,但解决方案似乎不适用于此方法。
function Get-GPOLink {
[CmdletBinding()]
param (
[Parameter(Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName)]
[Alias('DisplayName')]
[string[]]$Name
)
PROCESS {
foreach ($n in $Name) {
$problem = $false
try {
Write-Verbose -Message "Attempting to produce XML report for GPO: $n"
[xml]$report = Get-GPOReport -Name $n -ReportType Xml -ErrorAction Stop
}
catch {
$problem = $true
Write-Warning -Message "An error occured while attempting to query GPO: $n"
}
if (-not($problem)) {
Write-Verbose -Message "Returning results for GPO: $n"
[PSCustomObject]@{
'GPOName' = $report.GPO.Name
'LinksTo' = $report.GPO.LinksTo.SOMPath
'Enabled' = $report.GPO.LinksTo.Enabled
}
}
}
}
}
【问题讨论】:
标签: arrays powershell