In the world of Microsoft 365 administration, managing SharePoint sites efficiently is crucial for maintaining security, compliance, and operational smoothness. While the Microsoft 365 admin center provides a user-friendly interface for many tasks, there are times when you need more automation, customization, or bulk operations. That's where PowerShell comes in handy. That's why I created a tool to help me Get SharePoint Site Users. It is designed to retrieve and export user information from a SharePoint Online site, making it a valuable tool for admins and IT pros.
Whether you're auditing permissions, preparing reports, or troubleshooting access issues, this script can save you hours of manual work. In this blog post, I'll explain what the script does, break down how it works, and explore real-world scenarios where it shines. Let's get started!
How to Get SharePoint Site Users?
At its core, GetSharePointSiteUsers.ps1 is a PowerShell script that connects to a specified SharePoint Online site, fetches the list of users with access to that site, and exports the details to a CSV file. It leverages the PnP.PowerShell module, which is a popular community-driven library for interacting with SharePoint Online and other Microsoft 365 services.
Here's a high-level overview of its functionality:
- Authentication and Connection: The script uses Entra App authentication to connect to your SharePoint site via PnP.PowerShell.
- User Retrieval: It queries the site's users, including their display names, email addresses, user types (e.g., internal vs. external), and permission levels.
- Export to CSV: The collected data is formatted and saved to a CSV file, making it easy to analyze in tools like Excel or import into other systems.
- Error Handling and Logging: Basic error checking ensures the script handles common issues, such as invalid site URLs or authentication failures, with informative messages.
The script is straightforward and doesn't require advanced coding skills to run—just some basic PowerShell knowledge and the PnP.PowerShell module installed (which you can get via Install-Module -Name PnP.PowerShell).
.\GetSharePointSiteUsers.ps1 `
-SiteUrl “https://yourtenant.sharepoint.com/sites/YourSite” `
-ClientId “your-app-id” `
-TenantId “your-tenant-id” `
-Thumbprint “ABC123DEF456…”
The README in the Github folder also provides a usage example and prerequisites.
Why Use This PowerShell Script?
You might wonder: Why bother with a script when you can just log into the SharePoint admin center and view site permissions manually? The answer lies in efficiency, scalability, and automation.
- Automation for Repetitive Tasks: Manually checking users across multiple sites is tedious and error-prone. This script lets you automate the process, running it in batches or scheduling it via Task Scheduler.
- Detailed Reporting: The CSV output allows for easy sorting, filtering, and integration with tools like Power BI for visualizations or Excel for pivot tables.
- Compliance and Security: In regulated industries, regular audits are mandatory. This script provides a traceable, repeatable way to document who has access to sensitive data.
- Customization Potential: It's open-source, so you can tweak it—e.g., add filters for external users or integrate it with other scripts for broader Microsoft 365 reporting.
In short, if you're managing more than a handful of SharePoint sites, this script shifts you from reactive clicking to proactive scripting, freeing up time for more strategic work.
Meaningful Scenarios for Using the Script
Let's bring this to life with some practical examples. These scenarios highlight how GetSharePointSiteUsers can solve real problems in a Microsoft 365 environment.
Auditing for Compliance and Security Reviews
- This proactive approach helps prevent data breaches and ensures your organization stays compliant without disrupting daily operations.
Preparing for Employee Offboarding
- In a large enterprise, this could be automated via Azure Functions, triggering the script on HR notifications.
Troubleshooting Access Issues and Reporting
- This turns vague complaints into actionable fixes and provides metrics that justify IT investments.
Final Thoughts
The GetSharePointSiteUsers script is a gem for any Microsoft 365 admin looking to streamline user management in SharePoint Online. It's simple yet powerful, embodying the ethos of automation in IT. Check out this script and others on my Github repository: PowerShell for Microsoft 365.
