Powershell

Introduction

PowerShell is an essential tool for IT professionals managing Active Directory (AD), Azure, SharePoint, and Entra ID (formerly Azure AD). Automating tasks with PowerShell scripts saves time, reduces errors, and enhances efficiency. In this guide, we cover the top 10 PowerShell scripts for Active Directory and 5 must-have scripts for Azure, SharePoint, and Entra ID.


Top 10 PowerShell Scripts for Active Directory

1. Get All Users in AD

 Get-ADUser -Filter * -Properties DisplayName, EmailAddress | Select-Object DisplayName, EmailAddress

Retrieve a complete list of AD users with their names and email addresses.

2. Create a New AD User

 New-ADUser -Name "John Doe" -GivenName "John" -Surname "Doe" -SamAccountName "jdoe" -UserPrincipalName "jdoe@domain.com" -AccountPassword (ConvertTo-SecureString "P@ssword123" -AsPlainText -Force) -Enabled $true

Automate the creation of new Active Directory accounts.

3. Reset User Password

 Set-ADAccountPassword -Identity "jdoe" -Reset -NewPassword (ConvertTo-SecureString "NewP@ss123" -AsPlainText -Force)

Securely reset passwords for AD users.

4. Unlock a User Account

 Unlock-ADAccount -Identity "jdoe"

Quickly unlock a locked AD account.

5. Get Disabled Users

 Get-ADUser -Filter {Enabled -eq $false} | Select Name, SamAccountName

Identify disabled accounts for auditing or cleanup.

6. Add User to Group

 Add-ADGroupMember -Identity "ITTeam" -Members "jdoe"

Easily add users to AD groups.

7. Remove User from Group

 Remove-ADGroupMember -Identity "ITTeam" -Members "jdoe" -Confirm:$false

Remove users from groups without confirmation prompts.

8. Find Inactive Users

 Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 90.00:00:00

List users inactive for the last 90 days.

9. Export Users to CSV

 Get-ADUser -Filter * -Properties * | Select-Object Name, EmailAddress, Enabled | Export-Csv -Path "C:ADUsers.csv" -NoTypeInformation

Generate a full report of AD users.

10. Check User Group Membership

 Get-ADUser -Identity "jdoe" -Properties MemberOf | Select-Object -ExpandProperty MemberOf

View all groups a user belongs to.


5 Essential PowerShell Scripts for Azure, SharePoint, and Entra ID

1. Connect to Azure AD

 Connect-AzureAD

Start a session to manage users, groups, and licenses.

2. List All Azure AD Users

 Get-AzureADUser | Select DisplayName, UserPrincipalName

Retrieve a complete list of Azure AD users.

3. Create a SharePoint Online Site

 Connect-SPOService -Url "https://yourtenant-admin.sharepoint.com"
New-SPOSite -Url "https://yourtenant.sharepoint.com/sites/ProjectX" -Owner "admin@domain.com" -Title "ProjectX" -Template "STS#3" -StorageQuota 1024

Automate site creation in SharePoint Online.

4. Assign License in Entra ID

 Set-AzureADUserLicense -ObjectId "jdoe@domain.com" -AssignedLicenses @{Add="ENTERPRISEPACK"}

Quickly assign Microsoft 365 licenses to users.

5. Get SharePoint Site Usage Report

 Get-SPOSite -Limit All | Select URL, StorageUsageCurrent, Owner

Generate a report of SharePoint sites, owners, and storage usage.


Conclusion

PowerShell scripts are indispensable for IT management. Whether you’re handling user accounts, managing groups, or reporting site usage, these scripts save time and reduce errors. Start automating today to boost your productivity across Active Directory, Azure, SharePoint, and Entra ID.

Download PowerShell Scripts Cheat Sheet

You can download this guide for free, or support us with a donation via Stripe ❤️

Donate & Download Download Free Cheat Sheet (PDF)