September 14, 2024

Welcome, fellow SharePoint administrators! Just like Liverpool FC dominating the Champions League, it’s essential to master your SharePoint farm for peak performance.

Get ready to analyze your farm like a true football champ with our PowerShell script!

Before we begin, make sure you have the following:

  • SharePoint farm access: You should have administrative access to the SharePoint farm you want to analyze.
  • SharePoint Management Shell: Ensure that you have SharePoint Management Shell or PowerShell with SharePoint snap-ins installed on your machine.

Our PowerShell script, powered by a star-studded lineup of functions, covers key components of your SharePoint farm – just like Liverpool’s attacking trio! Let’s see how they score big:

Unleash your web applications’ prowess!

This function captures URL, version, content databases, upload size, and recycle bin retention period – playing like a relentless striker!

Like an agile winger, this function gathers site collection info – URL, owner, last content modification, site template, and content database – creating goal-scoring opportunities!

The midfield maestro!

This function captures web (subsite) details – URL, title, description, creation/modification dates – orchestrating the game with precision passing.

A solid defender guarding your data!

This function retrieves list/library info – title, URL, type, item count, and last modified date – ensuring a sturdy defense against errors.

The versatile all-rounder!

This function captures service application info – name, type, status, provisioning status, and associated servers – playing multiple roles with ease.

The captain of the team – farm administrators!

This function retrieves names and roles – providing strong leadership to your SharePoint farm.

Goalkeeper at the back!

This function gathers content database details – name, server, size, site collections, and last backup date – protecting your farm from data loss.

The impact player – apps in action!

This function captures app info – title, principal ID, installation date, marketplace URL, and status – making a game-changing difference.

The playmaker of communication!

This function gathers outgoing email settings – SMTP server address, from address, and reply-to address – delivering perfect passes for communication.

The vigilant defender!

This function retrieves alert details – site URL, title, user, associated list, event type, and delivery channels – ensuring you stay informed of crucial actions.

The timekeeper of your farm!

This function collects timer job info – name, display name, schedule, last run time, and status – keeping everything running smoothly.

The script iterates through the web applications, site collections, webs, lists/libraries, service applications, farm administrators, content databases, apps, outgoing email settings, alerts, and timer jobs to collect relevant information.

The gathered data is then stored in a CSV file.

Open SharePoint Management Shell or PowerShell with SharePoint snap-ins on your machine.

Ensure you have administrative access to the SharePoint farm you want to analyze. You need the full power of a star player to access all areas.

If needed, modify the script to fit your specific requirements. Tweak it like a manager making tactical adjustments before a big game.

Save the script with a .ps1 extension, for example, “SharePointFarmAnalysis.ps1”. Keep it safe like a prized trophy.

Navigate to the directory where the script is saved using the “cd” command. You need to be in the right position to kick-off.

Execute the script by entering the filename, e.g., “.\SharePointFarmAnalysis.ps1”. The script will start analyzing your SharePoint farm like a focused team on the pitch.

As the analysis runs, the PowerShell script will gather all the vital farm information, just like Liverpool orchestrating brilliant plays on the field.

After completing the analysis, check the results – a detailed CSV report named “SharePointFarmAnalysis.csv” will be generated in the same directory.

# Add SharePoint PowerShell Snap-in
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

# Function to get SharePoint Web Application details
function Get-SPWebApplicationDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.Administration.SPWebApplication]$WebApplication
    )

    $webAppDetails = @{
        "URL" = $WebApplication.Url
        "Version" = $WebApplication.ProductVersion
        "ContentDatabases" = $WebApplication.ContentDatabases.Count
        "MaxUploadSize" = $WebApplication.MaximumFileSize
        "RecycleBinRetention" = $WebApplication.RecycleBinRetentionPeriod
    }

    New-Object -TypeName PSObject -Property $webAppDetails
}

# Function to get SharePoint Site Collection details
function Get-SPSiteDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.SPSite]$SiteCollection
    )

    $siteDetails = @{
        "URL" = $SiteCollection.Url
        "Owner" = $SiteCollection.Owner.Name
        "LastContentModifiedDate" = $SiteCollection.LastContentModifiedDate
        "SiteTemplate" = $SiteCollection.RootWeb.WebTemplate + " - " + $SiteCollection.RootWeb.Configuration
        "ContentDB" = $SiteCollection.ContentDatabase.Name
    }

    New-Object -TypeName PSObject -Property $siteDetails
}

# Function to get SharePoint Web details
function Get-SPWebDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.SPWeb]$Web
    )

    $webDetails = @{
        "URL" = $Web.Url
        "Title" = $Web.Title
        "Description" = $Web.Description
        "Created" = $Web.Created
        "LastModified" = $Web.LastItemModifiedDate
        "IsRootWeb" = $Web.IsRootWeb
    }

    New-Object -TypeName PSObject -Property $webDetails
}

# Function to get SharePoint List/Library details
function Get-SPListDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.SPList]$List
    )

    $listDetails = @{
        "Title" = $List.Title
        "URL" = $List.DefaultViewUrl
        "Type" = $List.BaseType
        "ItemCount" = $List.ItemCount
        "LastModified" = $List.LastItemModifiedDate
    }

    New-Object -TypeName PSObject -Property $listDetails
}

# Function to get SharePoint Service Application details
function Get-SPServiceApplicationDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.Administration.SPServiceApplication]$ServiceApplication
    )

    $serviceAppDetails = @{
        "Name" = $ServiceApplication.Name
        "Type" = $ServiceApplication.GetType().Name
        "Status" = $ServiceApplication.Status
        "Provisioned" = $ServiceApplication.Provisioned
        "Servers" = ($ServiceApplication.Server | Select-Object -ExpandProperty Name) -join ","
    }

    New-Object -TypeName PSObject -Property $serviceAppDetails
}

# Function to get SharePoint Farm Administrator details
function Get-SPFarmAdminDetails {
    $farmAdmins = Get-SPFarm | Select-Object -ExpandProperty Identities
    $farmAdminDetails = @()

    foreach ($admin in $farmAdmins) {
        $adminDetails = @{
            "FarmAdministrator" = $admin.Name
            "Role" = $admin.Role
        }

        $farmAdminDetails += New-Object -TypeName PSObject -Property $adminDetails
    }

    $farmAdminDetails
}

# Function to get SharePoint Content Database details
function Get-SPContentDatabaseDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.Administration.SPContentDatabase]$ContentDatabase
    )

    $dbDetails = @{
        "Name" = $ContentDatabase.Name
        "Server" = $ContentDatabase.Server.Name
        "DatabaseSize" = $ContentDatabase.DiskSizeRequired
        "SiteCollections" = $ContentDatabase.Sites.Count
        "LastBackupDate" = $ContentDatabase.LastBackupDate
    }

    New-Object -TypeName PSObject -Property $dbDetails
}

# Function to get SharePoint App details
function Get-SPAppDetails {
    param (
        [Parameter(Mandatory=$true)]
        [Microsoft.SharePoint.Administration.SPApp]$App
    )

    $appDetails = @{
        "Title" = $App.Title
        "AppPrincipalId" = $App.AppPrincipalId
        "InstalledDate" = $App.InstalledDate
        "MarketplaceUrl" = $App.MarketplaceUrl
        "Status" = $App.Status
    }

    New-Object -TypeName PSObject -Property $appDetails
}

# Function to get SharePoint Outgoing Email Settings details
function Get-SPOutgoingEmailSettings {
    $outgoingEmailSettings = Get-SPWebApplication | Select-Object -ExpandProperty OutboundMailServiceInstance

    $emailDetails = @{
        "SMTPServer" = $outgoingEmailSettings.Server.Address
        "FromAddress" = $outgoingEmailSettings.Server.FromAddress
        "ReplyToAddress" = $outgoingEmailSettings.ReplyToAddress
    }

    New-Object -TypeName PSObject -Property $emailDetails
}

# Function to get SharePoint Alerts details
function Get-SPAlerts {
    $siteCollections = Get-SPSite -Limit All
    $alerts = @()

    foreach ($site in $siteCollections) {
        $web = $site.RootWeb
        $webAlerts = $web.Alerts

        foreach ($alert in $webAlerts) {
            $alertDetails = @{
                "Site" = $site.Url
                "Title" = $alert.Title
                "User" = $alert.User.Name
                "List" = $alert.List.Title
                "EventType" = $alert.EventType
                "DeliveryChannels" = ($alert.DeliveryChannels | Select-Object -ExpandProperty ToString) -join ","
            }

            $alerts += New-Object -TypeName PSObject -Property $alertDetails
        }

        $web.Dispose()
        $site.Dispose()
    }

    $alerts
}

# Function to get SharePoint Timer Jobs details
function Get-SPTimerJobs {
    $timerJobs = Get-SPTimerJob | Select-Object -Property Name, DisplayName, Schedule, LastRunTime, Status
    $timerJobs
}

# Get SharePoint Farm details
$farm = Get-SPFarm
$farmDetails = @{
    "FarmName" = $farm.Name
    "Version" = $farm.BuildVersion.ToString()
}

$csvData = New-Object System.Collections.Generic.List[PSObject]

# Get all Web Applications in the farm
$webApplications = Get-SPWebApplication

foreach ($webApp in $webApplications) {
    $webAppDetails = Get-SPWebApplicationDetails -WebApplication $webApp
    $csvData.Add($webAppDetails)

    # Get all Service Applications in the Web Application
    $serviceApplications = Get-SPServiceApplication -WebApplication $webApp

    foreach ($serviceApp in $serviceApplications) {
        $serviceAppDetails = Get-SPServiceApplicationDetails -ServiceApplication $serviceApp
        $csvData.Add($serviceAppDetails)
    }

    # Get Farm Administrators
    $farmAdmins = Get-SPFarmAdminDetails
    $csvData += $farmAdmins

    # Get all Content Databases in the Web Application
    $contentDatabases = $webApp.ContentDatabases

    foreach ($contentDb in $contentDatabases) {
        $dbDetails = Get-SPContentDatabaseDetails -ContentDatabase $contentDb
        $csvData.Add($dbDetails)
    }
}

# Get all Apps installed in the farm
$apps = Get-SPAppInstance
foreach ($app in $apps) {
    $appDetails = Get-SPAppDetails -App $app
    $csvData.Add($appDetails)
}

# Get Outgoing Email Settings
$emailSettings = Get-SPOutgoingEmailSettings
$csvData.Add($emailSettings)

# Get Alerts
$alerts = Get-SPAlerts
$csvData += $alerts

# Get Timer Jobs
$timerJobs = Get-SPTimerJobs
$csvData += $timerJobs

# Export the data to CSV
$csvData | Export-Csv -Path "SharePointFarmAnalysis.csv" -NoTypeInformation

Write-Host "SharePoint Farm analysis completed. The report has been saved to SharePointFarmAnalysis.csv."

Analyzing your SharePoint farm is essential for maintaining its performance, reliability, and overall health.

You can effortlessly gather comprehensive information about your SharePoint farm.

The generated CSV report will serve as a valuable reference for troubleshooting, optimization, and future planning.

We hope this guide has been helpful in understanding how to analyze your SharePoint farm using PowerShell.

Happy SharePoint administration!

Peace out!

Leave a Reply

Your email address will not be published. Required fields are marked *