Back to BlogMicrosoft 365 Tips

PowerShell Scripts for M365 Admins: A Beginner's Guide to Automation UK 2026

10 September 2026 6 min read
Photo by Jametlene Reskp on Unsplash

The reality: manual M365 administration is burning your time

If you're managing Microsoft 365 in the UK right now, you know the grind. Creating user accounts, assigning licences, resetting passwords, managing distribution groups – these tasks pile up fast, and they're identical every single time. The admin portal handles them, yes, but click by click, user by user, licence by licence.

Here's the uncomfortable truth: most M365 admins who don't use PowerShell are repeating the same 20 clicks fifty times a week. PowerShell scripts collapse that into a single command. Not just to save time, but because manually assigning 100 user licences is an error waiting to happen.

The good news? You don't need to be a programmer to use PowerShell. You need about five minutes of confidence and a few real examples that actually work in your environment.

What is PowerShell and why does it matter for M365?

PowerShell is a command-line tool built into Windows and baked into Microsoft 365. Unlike the graphical admin centre (which is fine for small tasks), PowerShell lets you send commands directly to Microsoft 365 services. One command can do what would take ten minutes in the GUI.

For M365 admins specifically, PowerShell connects to Exchange Online (email, mailboxes), Azure AD (user accounts, groups), and SharePoint. Once you're connected, you can bulk-edit users, automate licence assignment, generate reports, and enforce naming conventions across hundreds of resources at once.

The five biggest wins are:

  • Bulk user creation with consistent naming and licence assignment
  • Automatic password resets without the helpdesk being involved
  • Bulk licence management (add Teams, remove Outlook, etc.)
  • Mailbox forwarding, delegation, and compliance rules in seconds
  • Reporting: finding inactive users, licence spending, group membership drift
  • Most of these take 2-5 minutes of manual work per user in the admin centre. PowerShell does them in under a minute for 100 users.

    The three PowerShell commands you'll use 80% of the time

    Before you panic about learning a new language, know this: you can get seriously productive with just three concepts.

    1. Connect to Microsoft 365

    Before you can run any command, you need to authenticate. This is a one-time setup:

    ```

    Install-Module -Name ExchangeOnlineManagement -Force

    Connect-ExchangeOnline

    ```

    Run this once. PowerShell will ask for your admin credentials, and you're connected to Exchange Online. The same pattern works for Azure AD and SharePoint.

    2. Get information (the "Get" command)

    The "Get" command is your friend. It retrieves data without changing anything, so it's safe to experiment.

    ```

    Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, PrimarySmtpAddress

    ```

    This lists every mailbox and their email address. Change the properties in "Select-Object" to see different data: UserPrincipalName, ForwardingAddress, LitigationHold, whatever you need.

    Want to find users without a licence assigned?

    ```

    Get-User -ResultSize Unlimited | Where-Object {$_.LicenseDetails -eq $null}

    ```

    See the pattern? "Get-User" retrieves users. "Where-Object" filters them. "Select-Object" chooses which information to display.

    3. Make changes (the "Set" or "New" command)

    Once you know what you're looking for, you can make bulk changes.

    Add a forwarding address to 50 mailboxes:

    ```

    Get-Mailbox -Filter "Department -eq 'Sales'" | Set-Mailbox -ForwardingAddress sarah@example.com

    ```

    This finds everyone in Sales, then sets their mailbox to forward to Sarah. Instant done.

    Create a new distribution group:

    ```

    New-DistributionGroup -Name "London-IT-Team" -DisplayName "London IT Team" -Members @("user1@company.com", "user2@company.com")

    ```

    Real PowerShell scripts you can use today

    Here are three actual scripts that M365 admins run weekly in UK organisations.

    Script 1: Bulk disable inactive users

    ```

    $InactiveDate = (Get-Date).AddDays(-90)

    Get-Mailbox -ResultSize Unlimited | Where-Object {$_.LastLogonTime -lt $InactiveDate} | Foreach-Object {

    Disable-ADUser -Identity $_.UserPrincipalName

    Write-Output "$($_.DisplayName) has been disabled"

    }

    ```

    This finds users who haven't logged in for 90 days and disables them. It also logs which users were disabled, so you have a record.

    Script 2: Assign M365 licences to new users

    ```

    $Users = Get-Content "C:\NewUsers.txt"

    $Licence = "company:ENTERPRISEPACK"

    Foreach ($User in $Users) {

    Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $Licence

    Write-Output "$User has been licensed"

    }

    ```

    Add a list of email addresses to a text file (one per line), then this script assigns Enterprise licenses to all of them at once. Change "ENTERPRISEPACK" to whatever SKU you use (STANDARDPACK for Business Basic, etc.).

    Script 3: Generate a licence audit report

    ```

    $Report = @()

    Get-User -ResultSize Unlimited | Foreach-Object {

    $User = $_

    $Licences = Get-MsolUserLicense -UserPrincipalName $User.UserPrincipalName | Select-Object -ExpandProperty Licenses

    $Report += [PSCustomObject]@{

    DisplayName = $User.DisplayName

    Email = $User.PrimarySmtpAddress

    LicenceCount = ($Licences | Measure-Object).Count

    LastLogon = $User.LastLogonTime

    }

    }

    $Report | Export-Csv "C:\M365Report.csv" -NoTypeInformation

    ```

    This creates a CSV spreadsheet showing every user, how many licences they have, and when they last logged in. Invaluable for budget planning.

    Where to start: three beginner mistakes to avoid

    Mistake 1: Running scripts without testing first. Always run a "Get" command first to see what you're about to change. Once you've confirmed the results, swap "Get-Mailbox" for "Set-Mailbox" or "Disable-ADUser". Never run a change command blind.

    Mistake 2: Forgetting to save the output. Add "| Export-Csv "C:\output.csv" -NoTypeInformation" to the end of any command to save results. You'll thank yourself later when you need to show management what you changed.

    Mistake 3: Not logging in with the right permissions. Some commands require Global Admin or Exchange Admin role. If a command fails, check your role in the Microsoft 365 admin centre first.

    Learning PowerShell properly (and getting into M365 admin as a career)

    If you're new to IT and thinking about moving into M365 administration, PowerShell is one of the most valuable skills you can build. M365 administrators in the UK typically earn between £28,000 and £45,000 depending on experience and region (London roles push higher, often £50,000+).

    The Microsoft 365 Administrator Programme at SmoothOps 365 covers exactly this: real-world M365 admin scenarios, including automation and scripting. The course is built by someone who moved from healthcare into cloud engineering, so it's designed for career changers, not just IT veterans. You'll get hands-on PowerShell labs where you actually automate real admin tasks. Join the waitlist for the Microsoft 365 Administrator Programme today – it's currently coming soon, and early registrants get priority access.

    Next steps: your PowerShell lab environment

    Start safe. Create a test environment or use a sandbox tenant if your organisation offers one. Run the "Get" commands above. See what data they return. Then modify them slightly: change the department filter, adjust the date range, add more properties to the output.

    Once you're comfortable reading data, try a small "Set" command on a test account. Disable and re-enable it. Forward a test mailbox, then remove the forwarding. Build muscle memory with low-stakes changes.

    The real power of PowerShell isn't the scripts themselves – it's the confidence that you can automate anything you do more than twice. That's what separates admins who are always firefighting from admins who have time to plan.

    Frequently asked questions

    Do I need to know how to code to use PowerShell?

    No. PowerShell reads almost like English once you see a few examples. You're giving instructions to Microsoft 365, not writing software. Most M365 PowerShell work involves combining three to five pre-built commands; you don't need to invent new code.

    Can I break something if I run the wrong PowerShell command?

    Yes, but only if you use a "Set" or "Remove" command without testing first. Always run a "Get" version of the command first to see what you're about to change. Never run untested bulk change commands in your production environment.

    What's the difference between PowerShell and the M365 admin centre?

    The admin centre is a graphical tool; PowerShell is a command line. The admin centre is safer for one-off changes, but PowerShell is faster and necessary for bulk operations, scheduling, and reporting. Most admins use both.

    How often should M365 admins use PowerShell?

    Daily, if you're managing more than a few dozen users. Weekly, even if you're handling a small tenant. PowerShell saves the most time on repetitive tasks: user creation, licence audits, compliance checks, and bulk permission changes.

    Where can I practise PowerShell safely if I'm new?

    Ask your IT manager for a sandbox tenant or test user account. Most organisations have one. Alternatively, sign up for a free Microsoft 365 developer tenant (available at developer.microsoft.com). Run commands there first before using them in your live environment.

    Ready to start your IT career?

    SmoothOps 365 runs live instructor-led training every Saturday and Sunday. 3 months. 50 contact hours. Keep your job while you train.