Handy PowerShell commands to get SharePoint FARM Details

Recently I started working on a migration project to migrate the contents from SharePoint 2010 to SharePoint 2019. The first step was to analyze the current FARM. I had to write few PS scripts in order to get the FARM inventory. Here are some of the commands I used for getting the details. Hope this will help someone.

Get All WSP’s from the FARM

Many times you might need to download the wsp files from the central admin. There is no option from UI to download the wsp’s In order to do so, you need to have a PS script to get the WSP’s. This might require if you don’t have the backup of the wsp deployed and you want to upgrade to new version. Here is a small script which will download all the wsp’s from the FARM.

# Get list of all FARM solutions
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm=[Microsoft.SharePoint.Administration.SPFarm]::Local
foreach ($solution in $farm.Solutions) 
    {
        if ($solution.Deployed){
            Write-Host($solution.DisplayName)
            $solution.DisplayName >> c:\FARM_Solutions.txt 
        }          
    }
# Download all FARM solutions
#Add PS Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell

$farm = Get-SpFarm  
foreach($sol in $farm.Solutions){
$file = $farm.Solutions.Item($sol.Name).SolutionFile  
$file.SaveAs(“D:\WSPFiles\” + $sol.Name )  
}

Get All Webapplications

#Get list of all webapplications
Get-SPWebapplication > c:\SP_Webapplications.txt

Get All Content Databases

--Get list of all contentdatabases
get-spcontentdatabase > c:\SP_ContentDatabase.txt

Get Size of all Content Databases

#Get the size of each content database

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, @{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}} > c:\Content_DataBaseSize.txt

Get all Site collections

#Get list of all site collections

Get-SPSite -Limit All | Select Url,ContentDatabase | Format-Table -Wrap -AutoSize > C:\SiteCollections.txt

Get All Features

#Get all the features from FARM

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$farm=[Microsoft.SharePoint.Administration.SPFarm]::Local

foreach ($feature in $farm.FeatureDefinitions) 
{
if ($feature.Scope -eq "Farm" -and !$feature.Hidden){
Write-Host($feature.DisplayName) 
$feature.DisplayName >> c:\FARM_Features.txt
} 
}

Get all Content Sources

--Get all the content sources:-

add-pssnapin microsoft.sharepoint.powershell 
$ssa = Get-SPEnterpriseSearchServiceApplication 'Search Service Application'
Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa > c:\ContentSources.txt

Get last modified date/Webtemplate for the sites

Add-PSSnapin Microsoft.SharePoint.PowerShell
#Get all the site owners for sites and subsites for a webapp
#Get the web application
$WebAppURL= "<WebAppURL>"
$SiteCollection = Get-SPSite($WebAppURL)
$WebApp = $SiteCollection.WebApplication

write-host "Starting script"
#Write CSV- TAB Separated File) Header
"Site Collection URL `t Web URL `t WebTemplate `t LastModified " | out-file c:\SiteData.csv

#Loop through all site collections of the web app
foreach ($site in $WebApp.Sites)
{
# get the collection of webs
foreach($web in $site.AllWebs)
{
write-host "Looping site " $web.Url "was last modified on " $web.LastItemModifiedDate
#Find the webtemplate id
write-host $web.WebTemplate
#Send the Data to Log file
"$($site.url) `t $($web.url) `t $($web.WebTemplate) `t $($web.LastItemModifiedDate) " | Out-File c:\SiteData.csv -Append
}
}
#Dispose of the site object
$siteCollection.Dispose()
Write-host "Report Generated at same path of the powershell script SiteData.csv" -foregroundcolor green
write-host "Script Completed"

Get all Site Owners for sites

Add-PSSnapin Microsoft.SharePoint.PowerShell
#Get all the site owners for sites and subsites for a webapp
#Get all the sites
$sites = Get-SPSite -Limit All
#$sites = Get-SPSite <
write-host "Starting script"
#Write CSV- TAB Separated File) Header
"Site Collection URL `t Web URL `t SiteOwnerDisplayName `t SPGroup `t HasUniquePermissions `t LastModifiedDate" | out-file c:\InternalSitesData.csv

#Loop through all site collections of the web app
foreach ($site in $sites)
{
# get the collection of webs
foreach($web in $site.AllWebs)
{
write-host "Looping site " $web.Url
$lastModifiedDate = $web.LastItemModifiedDate
#check if the web has unique permissions
$hasUniquePermissions="False"
#ignore if its a root web as it will always have unique permissions
if($web.hasuniqueroleassignments -eq "True" -and !$web.IsRootWeb)
{
$hasUniquePermissions = "True"
}
elseif($web.IsRootWeb){
$hasUniquePermissions = "RootWeb"
}
$owners = "";
#get all the users from the owners group
foreach($ownerGroup in $web.AssociatedOwnerGroup)
{
foreach($owner in $ownerGroup.Users)
{
#append the users so that we can have only one row for each site in the csv file.
$owners += $owner.DisplayName + ";"
}
#if($owners -ne ""){
#Send the Data to Log file
# "$($site.url) `t $($web.url) `t $($owners) `t $($ownerGroup) `t $hasUniquePermissions `t $lastModifiedDate" | Out-File c:\InternalSitesData.csv -Append
# }
}
#there might be a scenario where users are directly given full control access.
$ownersWithFullControl = "";
foreach ($user in $web.Users) {
if ($web.DoesUserHavePermissions($user,[Microsoft.SharePoint.SPBasePermissions]::FullMask)) {
$owners += $user.Name +";"
}
}

if($owners -ne ""){
#Send the Data to Log file
"$($site.url) `t $($web.url) `t $($owners ) `t Full Control given directly `t $hasUniquePermissions `t $lastModifiedDate" | Out-File c:\InternalSitesData.csv -Append
}
}
}
#Dispose of the site object
$siteCollection.Dispose()
Write-host "Report Generated at same path of the powershell script SiteOwners.csv" -foregroundcolor green
write-host "Script Completed"

 

 

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.