Donnerstag, 27. Juni 2013

PowerShell: export XML content to text file (SCCM Configuration Item)

Hi,
this is one of my favourites scripts i did for SCCM, to manage Desired Configuration Management in a better way, and it was lost for a long time. It helps you to get settings extracted out of an SCCM configurtation item XML-File. Maybe you got some ".cab" files and want to know what settings are in there without using a tool which cannot export those data to a text file or an excel sheet.
What this script does is very simple, it reads the content of an xml file and creates an XML objects which can be used in powershell.

$path = "D:\xml-output.txt" #the text file you want to create
"New file" > $path
$myxml = [XML](get-content "D:\xml-file.xml")
$settings = $myxml.DesiredConfigurationDigest.BusinessPolicy.settings.rootcomplexsetting.ComplexSetting | foreach-object {$_.simplesetting}
"#############################################################################"  >> $path
" All Settings"  >> $path
"#############################################################################"  >> $path
$settings | %{$_.Rules.Rule} | select LogicalName,Operation,OperandA | ft -Property * -AutoSize | Out-String -Width 4000 >> $path
"#############################################################################"  >> $path
"Registry Values"  >> $path
$settings | %{$_.RegistryDiscoverySource} | ft -Property * -AutoSize | Out-String -Width 4000 >> $path
"#############################################################################"  >> $path
"WMI Entries"  >> $path
$settings | %{$_.WqlQueryDiscoverySource} | ft -Property * -AutoSize | Out-String -Width 4000   >> $path
This one is a very specific script for SCCM, but you can edit it and change it to your needs.

Customizing the output that it fits into a table can be done in different ways. The method I used in this example is described here: http://poshoholic.com/2010/11/11/powershell-quick-tip-creating-wide-tables-with-powershell/

Keine Kommentare:

Kommentar veröffentlichen