
初期にしっかりとした組織設計をしなかった ActiveDirectory は状況に合わせてOU構造がどんどん複雑になってしまい、それに合わせてGPOの数が増えて・・
ログオンスクリプトも設定してみたが、どこになんの設定が配布されているのか把握できないなんてことは別に珍しくなくプロの運用主任者がいない場合よく見るインフラあるある話です。
そんなある大手企業さんで、ログオンスクリプトでドライブマッピングをしていたのですがサーバー側を入れ替えた際に、どのログオンスクリプトで設定したのか調べてほしいといわれて作ったスクリプトになります。
GPO は Powershell から扱えますが、 xml で取り出してその中身を見るほうが簡単です。
xml を Powershell で読み取ってログオンスクリプトの中身をテキストで取得。
そして、中身に特定の文字が含まれているか確認し含まれている場合はリストに出力という流れになります。
そのまま使うことはあまりないかと思いますが、GPO の中で特定の設定があるかどうかなど改造することで確認することができるようになるかなと思います。
$GPO = Get-GPO -All
$GPO | % {
$GPOxml = $Type = $Command = $AHM = $Path = $text = $GPOname = $Link = $links = $null
$GPOname = $_.DisplayName
[xml]$GPOxml = Get-GPOReport -Name $GPOname -ReportType Xml
$Link = $GPOxml.gpo.LinksTo.sompath
$link | % {
$links += $_ + “`t”
}
$Type = $GPOxml.gpo.user.ExtensionData.extension.script.Type
if($Type -like “*Logon*”)
{
$Command = $GPOxml.gpo.user.ExtensionData.extension.script.Command
$Command | % {
if($_ -like ‘\\*’)
{
$AHM = get-content $_ | Where-object {$_ -like “*サーバーHost名*”}
if($AHM -ne $null)
{
$note = $null
$note = $GPOname + “`t” + $_ + “`t” + $links
$note | Out-File $env:UserProfile\desktop\Check_Logon.csv -Append
}
}
else
{
$text = $GPOxml.gpo.Identifier.Identifier.’#text’
$Path = “ADのセントラルのパス” + $text + “\User\Scripts\Logon\” + $_
$AHM = Get-Content $Path | Where-object {$_ -like “*サーバーのHost名*”}
if($AHM -ne $null)
{
$note = $null
$note = $GPOname + “`t” + $Path + “`t” + $links
$note | Out-File $env:UserProfile\desktop\Check_Logon.csv -Append
}
}
}
}
}
この記事へのコメントはありません。