Process RSOP XML file (with namespaces)

Here’s how to query the rsop xml reports generated from the script in the previous post. The xml file uses namespaces, so we need to take this into account when querying the files.

 

$xml = [xml] $(gc C:\RSOP_mycomputer.xml)
$XmlNamespaceManager = New-Object system.Xml.XmlNamespaceManager( $xml.NameTable )
$XmlNamespaceManager.AddNamespace("q1","http://www.microsoft.com/GroupPolicy/Settings/Security")
$XmlNamespaceManager.AddNamespace("q2","http://www.microsoft.com/GroupPolicy/Settings/Registry")
$XmlNamespaceManager.AddNamespace("q3","http://www.microsoft.com/GroupPolicy/Settings/PublicKey")

$xml.SelectNodes("//q1:SecurityOptions", $XmlNamespaceManager) `
| select @{Label="Name";Expression={[string]::Concat(  $_.KeyName, $_.SystemAccessPolicyName)}}, `
@{Label="Value";Expression={[string]::Concat( $_.SettingNumber,$_.SettingString, $( $_.SettingStrings `
| ForEach-Object -Begin{$output = @()} -Process {$output += $_.Value} -End { $([string]::join('|',$output))} ) )}} `
| sort Name

The important line is:

$xml.SelectNodes("//q1:SecurityOptions", $XmlNamespaceManager)

which takes into account the $xmlNamespaceManager. The following lines
are merely formatting etc. If you need to know more about it, drop me line.
You could save the output as a csv file then, and merge the files of
all servers for processing with Pivot tables in Excel. That way you can
report on all your servers and see if all settings are applied consistently.
Handy for troubleshooting….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s