Automating SharePoint Site Permissions Audit with PowerShell
Managing and auditing site permissions in SharePoint is crucial to ensure that sensitive information is protected and that users have appropriate access. This PowerShell script automates the process of retrieving and displaying permissions for a specified SharePoint site. With this script, administrators can easily conduct regular audits to maintain security and compliance within their SharePoint environment. This script will: 1. Connect to the SharePoint site using PowerShell. 2. Retrieve the list of users with permissions for the specified site. 3. Display the permissions assigned to each user. By leveraging this script, IT administrators can save time on permission management and enhance the integrity of access control within SharePoint.
# Install SharePoint Online Management Shell if not already installed
if (-Not (Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell)) {
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser -AllowClobber
}
# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
$credential = Get-Credential
Connect-SPOService -Url $siteUrl -Credential $credential
# Retrieve the site groups and their permissions
$groups = Get-SPOSiteGroup -Site $siteUrl
Write-Host "=== Permissions Audit for Site: $siteUrl ==="
foreach ($group in $groups) {
Write-Host "Group: $($group.Title)"
$users = Get-SPOGroupMembers -Group $group.Title -Site $siteUrl
foreach ($user in $users) {
Write-Host " User: $($user.LoginName)"
}
}
# Disconnect from SharePoint
Disconnect-SPOService
Write-Host "Permissions audit completed."Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in SharePoint & OneDrive
Monitor SharePoint Site Usage with PowerShell
2025-01-04Streamline SharePoint File Permissions Management with PowerShell
2025-01-04Managing File Permissions in SharePoint with PowerShell
2025-01-04Automate User Permissions Management in SharePoint with PowerShell
2024-12-24Efficiently List User Permissions in SharePoint with PowerShell
2024-12-24Efficiently Manage OneDrive File Permissions with PowerShell
2024-12-24Ready when you are.
Try ServerEngine free for 7 days.