如何进行PowerShell 脚本域策略管理
admin
2023-03-13 03:21:08
0

大中型企业中,会设置许多组策略进行日常运维管理 ,毕然里面也存在许多废弃的策略,需要我们定期清理我们的组策略信息。通常我们导出HTML报告方式来帮助我们分析组策略信息:

#1

首先需要加载GroupPolicy模块:

Import-Module GroupPolicy

将GPO导出为一个HTML报告:

Get-GPOReport -All -ReportType html -Path C:\GPOReports\GposReport.html

#2

将每个GPO导出生成自己的HTML报告中:

Get-GPO -All | %{
Get-GPOReport -name $_.displayname -ReportType html -path ("c:\GPOReports\"+$_.displayname+".html")
}

#3

让我们查询所有设置被禁用的GPO策略:

$reportFile = "c:\GPOReports\AllSettingsDisabledGpos.csv"
Set-Content -Path $reportFile -Value ("GPO Name,Settings")
Get-GPO -All | where{ $_.GpoStatus -eq "AllSettingsDisabled" } | % {
add-Content -Path $reportFile -Value ($_.displayName+","+$_.gpoStatus)
}

#4

查询没有应用到任何用户的Gpo策略

$reportFile = "c:\GPOReports\GPOApplyToPermissions.csv"
Set-Content -Path $reportFile -Value ("GPO Name,User/Group,Denied")
Get-GPO -All | %{
$gpoName = $_.displayName
[int]$counter = 0
$security = $_.GetSecurityInfo()
$security | where{ $_.Permission -eq "GpoApply" } | %{
add-Content -Path $reportFile -Value ($gpoName + "," + $_.trustee.name+","+$_.denied)
$counter += 1
}
if ($counter -eq 0)
{
add-Content -Path $reportFile -Value ($gpoName + ",NOT APPLIED")
}
}

#4

获取GPO,链接和WMI过滤器:

$reportFile = "c:\GPOReports\GPOLinksAndWMIFilters.csv"
Set-Content -Path $reportFile -Value ("GPO Name,# Links,Link Path,Enabled,No Override,WMI Filter")
$gpmc = New-Object -ComObject GPMgmt.GPM
$constants = $gpmc.GetConstants()
Get-GPO -All | %{
[int]$counter = 0
[xml]$report = $_.GenerateReport($constants.ReportXML)
try
{
$wmiFilterName = $report.gpo.filtername
}
catch
{
$wmiFilterName = "none"
}
$report.GPO.LinksTo | % {
if ($_.SOMPath -ne $null)
{
$counter += 1
add-Content -Path $reportFile -Value ($report.GPO.Name + "," + $report.GPO.linksto.Count + "," + $_.SOMPath + "," + $_.Enabled + "," + $_.NoOverride + "," + $wmiFilterName)
}
}
if ($counter -eq 0)
{
add-Content -Path $reportFile -Value ($report.GPO.Name + "," + $counter + "," + "NO LINKS" + "," + "NO LINKS" + "," + "NO LINKS")
}
}

#5

查询具有阻止GPO继承的组织单位:

Import-Module ActiveDirectory
$reportFile = "c:\GPOReports\OUsWithBlockInharit.csv"
set-Content -Path $reportFile -Value ("Block Inharitance OU Path")
Get-ADOrganizationalUnit -SearchBase "DC=Your,DC=Domain" -Filter * | Get-GPInheritance | Where-Object { $_.GPOInheritanceBlocked } | %{
add-Content -Path $reportFile -Value ($_.path)
}

相关内容

热门资讯

终于明白“云梦天穹.有没有挂?... 有 亲,根据资深记者爆料云梦天穹是可以开挂的,确实有挂(咨询软件无需打开...
玩家攻略科普“大庆划水麻将.怎... 家人们!今天小编来为大家解答大庆划水麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里...
我来教教您“新人海炸金花.可以... 您好:新人海炸金花这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9752949】很多玩家在这款...
【第一财经】“闽游麻将拼多多.... 网上科普关于“闽游麻将拼多多有没有挂”话题很是火热,小编也是针对闽游麻将拼多多作*弊开挂的方法以及开...
今日重大通报“微乐海南麻将.到... 您好:微乐海南麻将这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款...
直击“狡猾的吸入性肺炎”,这部... 潮新闻客户端 记者 金然 为积极响应国家“健康中国”与积极应对人口老龄化战略,探索电影创新路径与基层...
我来教教您“爱来掌中宝.到底有... 家人们!今天小编来为大家解答爱来掌中宝透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买...
重磅消息“火神牛牛.到底有挂吗... 有 亲,根据资深记者爆料火神牛牛是可以开挂的,确实有挂(咨询软件无需打开...
【第一资讯】“人人乐麻将.辅助... 【第一资讯】“人人乐麻将.辅助器?”外卦神器下载您好,人人乐麻将这个游戏其实有挂的,确实是有挂的,需...
今日重磅消息“丫丫古诗.辅助开... 有 亲,根据资深记者爆料丫丫古诗是可以开挂的,确实有挂(咨询软件无需打开...