RaSor's Blog

December 23, 2011

Cool powershell: From Xml to Csv in two lines

Filed under: Administration, Powershell, Sharepoint — Tags: — rasor @ 5:08 pm

With one-level xml you can convert xml to csv in two lines of powershell:

Create file Stsadm-EnumSites.xml:

cmd > stsadm -o enumsites -url http://teams > Stsadm-EnumSites.xml

<Sites Count="2">
  <Site Url="http://teams/" Owner="CONTOSO\XANDH" SecondaryOwner="CONTOSO\rinkr" ContentDatabase="WSS_Content_Teams" StorageUsedMB="0.6" StorageWarningMB="400" StorageMaxMB="500" />
  <Site Url="http://teams/commercial/AALT" Owner="CONTOSO\ECPD" ContentDatabase="WSS_Content_Teams" StorageUsedMB="77.4" StorageWarningMB="400" StorageMaxMB="500" />
</Sites>

Your converter code:

#read from file
[xml]$inputFile = Get-Content "Stsadm-EnumSites.xml"
#export xml as csv
$inputFile.Sites.ChildNodes | Export-Csv "Stsadm-EnumSites.csv" -NoTypeInformation -Delimiter:";" -Encoding:UTF8

Output: Stsadm-EnumSites.csv

"Url";"Owner";"SecondaryOwner";"ContentDatabase";"StorageUsedMB";"StorageWarningMB";"StorageMaxMB"
"http://teams";"CONTOSO\XANDH";"CONTOSO\rinkr";"WSS_Content_Teams";"0.6";"400";"500"
"http://teams/commercial/AALT";"CONTOSO\ECPD";;"WSS_Content_Teams";"77.4";"400";"500"

Cool :-)

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.