Monitor SharePoint Site Usage with PowerShell

Keeping track of site usage in SharePoint is essential for managing storage and understanding user engagement. This PowerShell script helps you retrieve and display key usage statistics for SharePoint sites, including the number of visitors and storage consumption. By automating this report, you can maintain better oversight of your SharePoint environment.
### Step 1: Install the SharePoint Online Management Shell
To effectively manage SharePoint, ensure you have the SharePoint Online Management Shell installed. This module is required to execute SharePoint-specific commands.
“`powershell

# Install the SharePoint Online Management Shell if it is not already installed
Install-Module -Name "Microsoft.Online.SharePoint.PowerShell" -Force

“`
### Step 2: Connect to SharePoint Online
You need to establish a connection to your SharePoint Online site. The following command will prompt you for your credentials.
“`powershell

# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"  # Replace with your SharePoint site URL
Connect-SPOService -Url $siteUrl

“`
### Step 3: Retrieve Site Usage Data
Use the following command to gather information about the usage statistics of the specified SharePoint site, such as site name, number of files, and storage used.
“`powershell

# Retrieve site usage data
$siteUsage = Get-SPOSite -Identity $siteUrl -Detailed | Select-Object Title, Owner, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, LastItemUserModifiedDate

“`
### Step 4: Display the Results
Display the site usage statistics in a table format to easily view relevant information.
“`powershell

# Display the site usage results
$siteUsage | Format-Table -AutoSize

“`
### Step 5: Export Results to CSV (Optional)
You can also export the usage data to a CSV file for documentation or review later.
“`powershell

# Export the site usage data to a CSV file
$siteUsage | Export-Csv -Path "C:\SharePoint_Site_Usage_Report.csv" -NoTypeInformation

“`
### Conclusion
This PowerShell script simplifies the task of monitoring SharePoint site usage, helping you maintain control over storage and ensure users are utilizing the resources effectively. Regularly reviewing site statistics allows for informed decision-making regarding storage management and user engagement.
For more automated solutions for server management and optimization, check out ServerEngine at [https://serverengine.co](https://serverengine.co). Empower your infrastructure with our robust set of tools!