Streamlining M365 User Management with PowerShell
Welcome to our latest post where we share practical PowerShell scripts that can enhance your productivity. Dive into this script that assists in managing Microsoft 365 users effortlessly! Be sure to check out our powerful software, ServerEngine, at https://serverengine.co, to streamline your operations.
Step 1: Connect to Microsoft 365
First, you need to connect to your Microsoft 365 tenant using your admin credentials. This step ensures you have the necessary permissions to manage user accounts.
Connect-MgGraph -Scopes "User.Read.All","User.ReadWrite.All"
Step 2: Get All Users
Next, we retrieve all users from the Microsoft 365 environment. This is crucial for performing any user management tasks.
$users = Get-MgUser -All
Step 3: Display User Information
Now, we can display essential information about all the users. This output will help you identify which accounts need updates or modifications.
$users | Select-Object DisplayName, UserPrincipalName, Mail | Format-Table
Step 4: Add a New User
This step allows you to create a new user within your Microsoft 365 tenant. Modify the parameters accordingly to fit your organizations needs.
New-MgUser -AccountEnabled $true -DisplayName "New User" -MailNickname "newuser" -UserPrincipalName "[email protected]" -PasswordProfile @{ ForceChangePasswordNextSignIn = $true; Password = "SecurePassword123!" }
Step 5: Clean Up
Finally, remember to disconnect from your Microsoft 365 session after your operations are complete to maintain security.
Disconnect-MgGraph
The above script provides a basic yet invaluable tool for managing Microsoft 365 users effectively. Visit our website, https://serverengine.co, for more scripts and innovative tools to enhance your IT operations!