Script:
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\SiteDetailsInXMLFormatPatch-$LogTime.rtf"
- # Add SharePoint PowerShell Snapin
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
- start-transcript $logfile
- $SiteCollection = get-spsite -limit all
- # Set the File Name
- $filePath = $scriptbase + "\" + "SiteDetails.xml"
- # Create The Document
- $XmlWriter = New-Object System.XMl.XmlTextWriter($filePath,$Null)
- # Write the XML Decleration
- $xmlWriter.WriteStartDocument()
- # Write Root Element
- $xmlWriter.WriteStartElement("SiteCollectionDetails") #Opening site collection details
- foreach($site in $siteCollection)
- {
- write-host "Collecting information for the site collection " $site.url -fore magenta
- $xmlWriter.WriteStartElement("SiteCollection") #Opening SiteCollection URL
- $xmlWriter.WriteAttributeString("URL", $Site.url)
- $xmlWriter.WriteAttributeString("SubSiteCount", $Site.allwebs.count)
- foreach($web in $site.allwebs)
- {
- write-host "collecting information for the web " $web.url -fore blue
- $xmlWriter.WriteStartElement("Webs") #Opening Webs
- $xmlWriter.WriteAttributeString("URL", $web.url)
- $xmlWriter.WriteAttributeString("ListCount", $web.lists.count)
- foreach($list in $web.lists)
- {
- write-host "Collecting information for the list " $list.title -fore yellow
- $xmlWriter.WriteStartElement("List") #Opening List
- $xmlWriter.WriteAttributeString("Title", $List.Title)
- $xmlWriter.WriteAttributeString("ItemCount", $list.items.count)
- foreach($item in $list.items)
- {
- write-host "Processing item " $item.id -fore cyan
- $xmlWriter.WriteStartElement("Item") #Opening Item
- $xmlWriter.WriteAttributeString("ID", $Item.ID)
- $xmlWriter.WriteAttributeString("VersionCount", $Item.versions.count)
- $xmlWriter.WriteEndElement() #Closing Item
- }
- $xmlWriter.WriteEndElement() #Closing List
- }
- $xmlWriter.WriteEndElement() #closing Webs
- }
- $xmlWriter.WriteEndElement() #Closing SiteCollection URL
- }
- $xmlWriter.WriteEndElement() #closing site collection details
- # End the XML Document
- $xmlWriter.WriteEndDocument()
- # Finish The Document
- $xmlWriter.Finalize
- $xmlWriter.Flush
- $xmlWriter.Close()
- write-host "SCRIPT COMPLETED" -fore green
- stop-transcript
