################################################################################## # # # Script name: Get-SiteInformation.ps1 # Author: goude@powershell.nu # Homepage: www.powershell.nu # # ################################################################################## param ([string]$Url, [switch]$help, [switch]$ToCsv) function GetHelp() { $HelpText = @" DESCRIPTION: NAME: Get-SiteInformation.ps1 Gets Information about Sites in SharePoint PARAMETERS: -Url Sharepoint Url (Required) -ToCsv Exports the Information to a Csv file (Optional) -help Prints the HelpFile (Optional) SYNTAX: ./Get-SiteInformation.ps1 -Url http://wss Gets Information about Sites in SharePoint and returns it to the Prompt ./Get-SiteInformation.ps1 -Url http://wss -ToCsv Gets Information about Sites in SharePoint and Exports the information to a Csv File in the current Folder ./Get-SiteInformation.ps1 -help Displays the help topic for the script "@ $HelpText } function Set-SiteInformation ([string]$Url, [switch]$ToCsv) { if($ToCsv) { $Path = $pwd.ToString() + "\SiteInformation.csv" $SiteInfo = Get-SiteInformation $Url $SiteInfo | Export-Csv $Path -NoTypeInformation } else { $SiteInfo = Get-SiteInformation $Url $SiteInfo } } function Get-SiteInformation ([string]$Url) { $SPSite = New-Object Microsoft.SharePoint.SPSite($Url) $AllWebs = $SPSite.AllWebs $AllWebs | ForEach { if ($_.Theme -eq "") { $Theme = "Default Theme" } else { $Theme = $_.Theme } $SiteInformation = New-Object PsObject $SiteInformation | Add-Member -memberType NoteProperty "Name" -Value $_.Name $SiteInformation | Add-Member -memberType NoteProperty "Title" -Value $_.Title $SiteInformation | Add-Member -memberType NoteProperty "Description" -Value $_.Description $SiteInformation | Add-Member -memberType NoteProperty "Theme" -Value $Theme $SiteInformation | Add-Member -memberType NoteProperty "WebTemplate" -Value $_.WebTemplate $SiteInformation | Add-Member -memberType NoteProperty "Author" -Value $_.Author $SiteInformation | Add-Member -memberType NoteProperty "Created" -Value $_.Created $SiteInformation | Add-Member -memberType NoteProperty "Modified" -Value $_.LastItemModifiedDate $SiteInformation | Add-Member -memberType NoteProperty "Sites" -Value ($_.Webs).Count $SiteInformation | Add-Member -memberType NoteProperty "Users" -Value $_.SiteUsers.Count $SiteInformation | Add-Member -memberType NoteProperty "ParentWeb" -Value $_.ParentWeb $SiteInformation | Add-Member -memberType NoteProperty "Url" -Value $_.Url $SiteInformation | Add-Member -memberType NoteProperty "ServerRelativeUrl" -Value $_.ServerRelativeUrl $SiteInformation | Add-Member -memberType NoteProperty "ID" -Value $_.ID $SiteInformation } $SPSite.Dispose() } if ($help) { GetHelp } if ($Url -AND $ToCsv) { Set-SiteInformation $Url -ToCsv } if ($Url -AND !$ToCsv) { Set-SiteInformation $Url }