Script samples

Scripts and tools

Each sample solves one real admin task and shows it in every tool that can do it: PnP PowerShell, Microsoft Graph PowerShell, CLI for Microsoft 365, Exchange Online PowerShell, the ActiveDirectory module and the Configuration Manager module.

19 shown

>_ ScriptReport30 Nov 2026

Report site collection administrators for every site

Lists every site collection in the tenant with its site collection administrators, so you can find sites with no owner, a single owner, or a former employee still holding admin rights. Useful before a migration and in quarterly access reviews.

PnP PowerShellSPO Management ShellCLI for Microsoft 365
PUPriyanshu UpadhyayView script →
>_ ScriptSecurity29 Nov 2026

Find sites with external sharing turned on

Reports the sharing capability of every site so security and migration teams can see which sites allow anonymous links or guests, and compare them with the tenant default.

PnP PowerShellSPO Management Shell
PUPriyanshu UpadhyayView script →
>_ ScriptReport28 Nov 2026

OneDrive storage usage per user

Builds a OneDrive storage report for capacity planning and migration sizing: owner, storage used, file count and last activity. Two approaches: the SharePoint admin view of personal sites, and the Microsoft Graph usage report.

SPO Management ShellMicrosoft Graph PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptSecurity27 Nov 2026

Find users who have not signed in for 90 days

Finds enabled member accounts with no interactive or non-interactive sign-in in the last 90 days, a common first step for licence reclamation and before migration waves.

Microsoft Graph PowerShellGraph REST API
PUPriyanshu UpadhyayView script →
>_ ScriptReport26 Nov 2026

Licence assignment report by SKU

Shows how many licences you own, how many are assigned, and which users hold each SKU, with friendly names for the SKU part numbers. Run it before buying more licences or planning a migration.

Microsoft Graph PowerShellCLI for Microsoft 365
PUPriyanshu UpadhyayView script →
>_ ScriptProvision25 Nov 2026

Assign licences in bulk from a CSV

Assigns a licence to every user in a CSV, sets the usage location first when it is missing, and optionally disables service plans such as Exchange Online for users who are waiting for a mailbox migration.

Microsoft Graph PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptSecurity24 Nov 2026

Guest users, invitation state and last sign-in

Lists every guest with where they came from, whether they accepted the invitation and when they last signed in, so you can clean up stale guests before an audit or a tenant migration.

Microsoft Graph PowerShellCLI for Microsoft 365
PUPriyanshu UpadhyayView script →
>_ ScriptReport23 Nov 2026

Mailbox permissions report: Full Access, Send As, Send on Behalf

Exports every delegated permission on user and shared mailboxes in one file. Run it before a mailbox migration (Send on Behalf never moves on its own) and for access reviews.

Exchange Online PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptSecurity22 Nov 2026

Find mailboxes that forward mail outside the company

Finds forwarding set on the mailbox and in inbox rules that sends mail to external addresses, one of the most common signs of a compromised account and a common leftover after a migration.

Exchange Online PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptMigrate21 Nov 2026

Migration batch in-progress report

The daily report for a mailbox migration: every user in the active batches with status, percent complete, size, skipped items and the error summary, split into one CSV per status.

Exchange Online PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptMigrate20 Nov 2026

Validate target MailUsers before a cross-tenant batch

Compares the source mailbox export with the target MailUsers and flags every user who would fail: missing object, ExchangeGuid or ArchiveGuid mismatch, missing x500, or a mailbox that already exists.

Exchange Online PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptReport19 Nov 2026

Teams with no owner or only one owner

Finds teams that have lost their owners, usually because people left. Ownerless teams cannot be managed by members and become a governance and migration risk.

Microsoft Graph PowerShellPnP PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptReport18 Nov 2026

Non-compliant Intune devices with the failing policy

Lists every non-compliant managed device with its primary user, OS and last check-in, and the compliance policies it fails, so the service desk can chase the right people.

Microsoft Graph PowerShellGraph REST API
PUPriyanshu UpadhyayView script →
>_ ScriptCleanup17 Nov 2026

Stale Intune devices not seen for 90 days

Finds managed devices that have not checked in for 90 days. Review the list, then retire or delete them so device counts, compliance reports and licence numbers are accurate.

Microsoft Graph PowerShell
PUPriyanshu UpadhyayView script →
>_ ScriptReport16 Nov 2026

Export Windows Autopilot devices with group tags

Exports every Autopilot device with serial number, model, group tag and profile assignment status. Use it to check readiness before a device migration and to find devices still registered in the old tenant.

Microsoft Graph PowerShellGraph REST API
PUPriyanshu UpadhyayView script →
>_ ScriptCleanup15 Nov 2026

Stale Active Directory computer accounts

Finds computer accounts that have not logged on to the domain for 90 days, with their OU and operating system, so you can disable them before they are deleted.

ActiveDirectory module
PUPriyanshu UpadhyayView script →
>_ ScriptReport14 Nov 2026

Export nested group membership

Expands every nested group to list the real users who get access through a group, including the path they inherit it through. Essential before migrating groups or file share permissions.

ActiveDirectory module
PUPriyanshu UpadhyayView script →
>_ ScriptTroubleshoot13 Nov 2026

Inactive Configuration Manager clients in a collection

Lists devices in a collection whose ConfigMgr client is inactive or missing, with the last activity time, so you can repair clients before a deployment or a co-management change.

ConfigurationManager modulePowerShell (WMI on the site server)
PUPriyanshu UpadhyayView script →
>_ ScriptTroubleshoot12 Nov 2026

Check Entra Connect sync health from both sides

Checks hybrid identity health from the cloud (last directory sync time, password hash sync) and from the sync server (scheduler, staging mode, next cycle). Run it before a migration wave that depends on new synced accounts.

Microsoft Graph PowerShellADSync module (sync server)
PUPriyanshu UpadhyayView script →