Skip to content

Instantly share code, notes, and snippets.

@PCfromDC
Last active June 13, 2016 18:19
Show Gist options
  • Save PCfromDC/57e80c08ec402b461622 to your computer and use it in GitHub Desktop.
Save PCfromDC/57e80c08ec402b461622 to your computer and use it in GitHub Desktop.
This PowerShell script gets all of your SharePoint Farm's information
#Get Backup Path
$bkdir = read-host("Enter Folder Location eg: (C:\temp)") # Get Backup Path!
if ($bkdir.EndsWith("\")){$bkdir = $bkdir.TrimEnd("\")}
# Set Backup Path if you want to hard code your path
#$bkdir = "\\serverName\Shared\Temp" (optional "C:\Temp")
# Verify folder exists
if ((test-path $bkdir) -eq $false ) # Verify folder else create it...
{
[IO.Directory]::CreateDirectory($bkdir)
}
# Add Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
Start-SPAssignment –Global
$spSites = Get-SPSite -Limit All
$spWAs = Get-SPWebApplication -IncludeCentralAdministration
$csvs = @()
#Get Web Application Data
Write-Host("Getting Web Application Data")
$spWAs | select Name, DisplayName, Id, Url, ApplicationPool, @{Expression={$_.ApplicationPool.Name}}, @{Expression={$_.ApplicationPool.UserName}}, DefaultQuotaTemplate | Export-CSV $bkdir\SPWebApplication.csv
$csvs += $bkdir + '\SPWebApplication.csv'
#Get Site Collection Data
Write-Host("Getting Site Collection Data")
$spSites | select Id, HostName, Url, Owner,WebApplication, ContentDatabase, RootWeb, LastContentModifiedDate, @{Expression={$_.Usage.Storage}} | Export-CSV $bkdir\SPSite.csv
$csvs += $bkdir + '\SPSite.csv'
#Get Site Data
Write-Host("Getting Site Data")
$spSites | Get-SPWeb -Limit All | select ID, Title, Author, Url, WebTemplate, LastItemModifiedDate, IsRootWeb | Export-CSV $bkdir\SPWeb.csv
$csvs += $bkdir + '\SPWeb.csv'
#Get Site Admin Data
Write-Host("Getting Site Administration Data")
Get-SPSiteAdministration -Limit All | Select Url, Title,OwnerLoginName, SecondaryContactLoginName, UsersCount, RootWebTemplate | Export-CSV $bkdir\SPSiteAdmin.csv
$csvs += $bkdir + '\SPSiteAdmin.csv'
#Get SandBox Solutions
Write-Host("Getting SandBox Solutions")
# Create Table
$table = New-Object system.Data.DataTable “table”
# Create Columns
$col1 = New-Object system.Data.DataColumn Name,([string])
$col2 = New-Object system.Data.DataColumn SolutionId,([string])
$col3 = New-Object system.Data.DataColumn Status,([string])
$col4 = New-Object system.Data.DataColumn HasAssemblies,([string])
$col5 = New-Object system.Data.DataColumn URL,([string])
# Add the Columns
$table.columns.add($col1)
$table.columns.add($col2)
$table.columns.add($col3)
$table.columns.add($col4)
$table.columns.add($col5)
foreach ($site in $spSites){
$solution = $site | Get-SPUserSolution
if ($solution.Name.length -gt 1){
# Add Row Information
$row = $table.NewRow()
$row.Name = $solution.Name
$row.SolutionId = $solution.SolutionId
$row.Status = $solution.Status
$row.HasAssemblies = $solution.HasAssemblies
$row.URL = $site.Url
# Add Row to Table
$table.Rows.Add($row)
}
}
# Output Table
$table | Export-CSV $bkdir\SPUserSolution.csv
$csvs += $bkdir + '\SPUserSolution.csv'
#Get Process Accounts
Write-Host("Getting Process Accounts")
Get-SPProcessAccount | select Name, SecurityIdentifier | Export-CSV $bkdir\SPProcesAcct.csv
$csvs += $bkdir + '\SPProcesAcct.csv'
#Get Managed Accounts
Write-Host("Getting Managed Accounts")
Get-SPManagedAccount | select TypeName, UserName, DiplayName, Sid, AutomaticChange, Name, Id, Status | Export-CSV $bkdir\SPManagedAccts.csv
$csvs += $bkdir + '\SPManagedAccts.csv'
#Get Alternate URLs
Write-Host("Getting Alternate URLs")
Get-SPAlternateUrl | select IncomingUrl, UrlZone, PublicUrl | Export-CSV $bkdir\SPAlternateUrl.csv
$csvs += $bkdir + '\SPAlternateUrl.csv'
#Get Managed Paths
Write-Host("Getting Managed Paths")
$spWAs | Get-SPManagedPath | Export-CSV $bkdir\SPManagedPath.csv
$csvs += $bkdir + '\SPManagedPath.csv'
#Get Solutions
Write-Host("Getting Farm Solutions")
Get-SPSolution | select SolutionId, Name, DisplayName, Deployed, DeploymentState, SolutionFile, ContainsGlobalAssembly, ContainsWebApplicationResource, JobExists, Version | Export-CSV $bkdir\SPSolution.csv
$csvs += $bkdir + '\SPSolution.csv'
#Get Features
Write-Host("Getting Features")
Get-SPFeature | select SolutionId, Name, DisplayName, Scope, RootDirectory, Status | Sort -Property Scope,DisplayName | Export-CSV $bkdir\SPFeature.csv
$csvs += $bkdir + '\SPFeature.csv'
#Get SP Databases
Write-Host("Getting SP Databases")
Get-SPDatabase | select DisplayName, Server, ID, Status | Export-CSV $bkdir\SPDatabase.csv
$csvs += $bkdir + '\SPDatabase.csv'
#Get Content Databases
Write-Host("Getting Content Databases")
Get-SPContentDatabase | select Name, DisplayName, Id, Server, PreferredTimerServiceInstance, CurrentSiteCount, WarningSiteCount, MaximumSiteCount, WebApplication, Exists, IsReadOnly, DiskSizeRequired, NeedsUpgradeIncludeChildren, NeedsUpgrade, Status, Version | Export-CSV $bkdir\SPContentDatabase.csv
$csvs += $bkdir + '\SPContentDatabase.csv'
#Get Services
Write-Host("Getting Service Instances")
Get-SPServiceInstance | select TypeName, Service, Id, Server, NeedsUpgradeIncludeChildren, NeedsUpgrade, Status, Version | Export-CSV $bkdir\SPServiceIntances.csv
$csvs += $bkdir + '\SPServiceIntances.csv'
#Get Service Applications
Write-Host("Getting Service Applications")
Get-SPServiceApplication | select Name, DisplayName, TypeName, Id, IisVirtualDirectoryPath, ApplicationPool, Service, DefaultEndpoint, Version | Export-CSV $bkdir\SPServiceApplication.csv
$csvs += $bkdir + '\SPServiceApplication.csv'
#Get Web Templates
Write-Host("Getting Web Templates")
Get-SPWebTemplate | select ID, Title, Name, Description, Lcid, IsCustomTemplate, IsRootWebOnly, IsSubWebOnly | Export-CSV $bkdir\SPWebTemplate.csv
$csvs += $bkdir + '\SPWebTemplate.csv'
#Get Service Application Pools
Write-Host("Getting Service Application Pool Accounts")
Get-SPServiceApplicationPool | select Id, Name, ProcessAccountName | Export-CSV $bkdir\SPAppPoolAccounts.csv
$csvs += $bkdir + '\SPAppPoolAccounts.csv'
#Get Site Structure for All Web Applications and Site Collections
Write-Host("Getting Site Structure for Farm")
$webs = @()
foreach ($spWA in $spWAs)
{
$sites = Get-SPSite -WebApplication $spWA -Limit All
foreach ($site in $sites) {
$webs += Get-SPWeb -Site $site | Select Title, URL, ID, ParentWebID
}
}
$webs | Export-CSV $bkdir\SPFarmSiteStructure.csv
$csvs += $bkdir + '\SPFarmSiteStructure.csv'
Stop-SPAssignment –Global
@levesquesamuel
Copy link

Thanks for this script, in my own version I've added a line to display the deployed WebApplications : Get-SPSolution | select SolutionId, Name, DisplayName, Deployed, DeploymentState, SolutionFile, ContainsGlobalAssembly, ContainsWebApplicationResource, JobExists, Version, @{Name='DeployedWebApplications';Expression={[string]::join(";", ($_.DeployedWebApplications))}} | Export-CSV $bkdir\SPSolution.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment