LoginSignup
1
5

More than 5 years have passed since last update.

ADに登録している全グループポリシーを、1つ1つグループポリシー名のhtmlファイルに出力する

Last updated at Posted at 2018-10-06

前提:
ADサーバーで実行してください

懸念:
1500ポリシーのとき、大体1分で終わります
CPU結構使います(+50〜60% t1.midium)
  嫌なら「Get-GPOReport -Guid」の前にsleep入れてください
  (sleep分xポリシーの時間がかかるようになります)


Get-ADOrganizationalUnit -Filter 'Name -like "*"'| %{Get-GPInheritance -target $_} | %{$_.gpolinks} |%{Get-GPOReport -Guid $_.Gpoid -ReportType Html -Path c:\gpotest\$($_.Displayname).html}

sleep 版


Get-ADOrganizationalUnit -Filter 'Name -like "*"'| %{Get-GPInheritance -target $_} | %{$_.gpolinks} |%{sleep 1;Get-GPOReport -Guid $_.Gpoid -ReportType Html -Path c:\gpotest\$($_.Displayname).html}

余談

GPO情報をhtml出力する「Get-GPOReport」コマンドレットをループ処理中で実行するとCPUを大分使うのは、コマンドレットが実行終了しているにも関わらず、バックグラウンドにプロセスが残っているためです。
回避するためにsleepを使いましたが、もっと少し滑らかに処理を回すために、セマフォもどき関数を作りました。(実際にはバックグラウンドプロセスの終了を待てないから、"もどき"です)
AD関連のコマンドレットはCPU、メモリ消費が多くなるので、有効かなと思います。


# カウント変数初期化
$script:counting = 0

# 指定したスクリプトブロック${scriptbl}を${number}回実行するごとに${sleeptime}秒待つ、セマフォもどき関数
function do-some-block-and-sleep ([scriptblock]${scriptbl},${number},${sleeptime}) { 
    $script:counting++
        switch ($script:counting) { 
            {$_ % ${number} -ne 0} {& $scriptbl} 
            {$_ % ${number} -eq 0} {& $scriptbl; sleep ${sleeptime}; $script:counting = 0}  
        }
}

# GPOを1つ1つhtml出力 30個出力するごとに2秒sleep =実行時間 100秒 (gpo1500個の時)
Get-ADOrganizationalUnit -Filter 'Name -like "*"'| %{Get-GPInheritance -target $_} | %{$_.gpolinks} |%{ $gpoid = $_.Gpoid; $displayname = $_.Displayname; do-some-block-and-sleep {Get-GPOReport -Guid $gpoid -ReportType Html -Path c:\gpohtml\$($displayname).html} 30 2}

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5