TinyAddicts is a series of ultra-short, ultra-useful scripts and snippets. No fluff – just pure, working code. Perfect for admins, devs, and anyone who values their time.
Scenario
You want to check who invited external users into your Microsoft 365 tenant – and when. Here’s how to list all guest accounts with key info like creation date and account status.
Code
1 2 |
Get-MgUser -Filter "userType eq 'Guest'" -All -Property DisplayName,UserPrincipalName,CreatedDateTime,AccountEnabled | Select-Object DisplayName, UserPrincipalName, CreatedDateTime, AccountEnabled |
Sample Output
1 2 3 4 |
DisplayName UserPrincipalName CreatedDateTime AccountEnabled ------------ ------------------- ---------------- --------------- John External john@gmail.com 2024-11-03T10:22Z True Jane Partner jane@partner.org 2023-05-18T15:55Z False |
Notes
- Requires
User.Read.All
permission. -Property
is essential — otherwiseCreatedDateTime
andAccountEnabled
won’t show up.- Great for security reviews and cleanup of old guest accounts.
- Export to CSV? Just add:
1 |
... | Export-Csv ".\GuestUsers.csv" -NoTypeInformation -Encoding UTF8 |
More bite-sized scripts in the TinyAddicts series – simple tools, serious impact.