Friday, June 20, 2025
HomePowershellManaging Visitor Customers in PowerShell with Microsoft Graph API – SID-500.COM

Managing Visitor Customers in PowerShell with Microsoft Graph API – SID-500.COM


PowerShell

Managing Visitor Customers in PowerShell with Microsoft Graph API

In at present’s collaborative work environments, inviting visitor customers to entry organizational assets has change into a standard follow. PowerShell, mixed with Microsoft Graph API (mggraph), gives a strong solution to handle these visitor customers. This weblog publish explores the best way to use PowerShell and mggraph to handle visitor customers, with sensible examples for example key ideas. Let’s dive in.

Introduction to Visitor Customers and Microsoft Graph API

Visitor customers are exterior customers who’re granted entry to your group’s assets. Microsoft Graph API, a unified endpoint for accessing knowledge throughout Microsoft companies, allows directors to automate the administration of those visitor customers via PowerShell scripts.

Putting in Graph API and connecting to the Cloud

Earlier than diving into the examples, we nonetheless have some work to do, specifically we have to connect with the cloud.

# Micrsoft Graph Module
Set up-Module Microsoft.Graph -AllowClobber -Drive

# Connect with Cloud
Join-MgGraph -Scopes 'Consumer.ReadWrite.All'  
Get-MgContext | Choose-Object -ExpandProperty Scopes

Inviting | Retrieving | Eradicating Visitor Customers

Listed here are some examples of the best way to invite visitor customers, retrieve (show) visitor customers and eventually take away visitor customers.

# Invite Visitor Consumer
New-MgInvitation -InvitedUserDisplayName "Hans Womanizer" -InvitedUserEmailAddress pewa2303@gmail.com `
-InviteRedirectUrl "https://myapplications.microsoft.com" -SendInvitationMessage:$true

# Retrieve Visitor Customers
Get-MgUser -Filter "userType eq 'Visitor'" -All 
Get-MgUser -Filter "userType eq 'Visitor' and externalUserState eq 'PendingAcceptance'" -All 

# Take away Visitor Consumer
Take away-MgUser -UserId pewa2303_gmail.com#EXT#@sid500.onmicrosoft.com

Disconnect

Final however not least, we disconnect from the ms graph API.

Hope this was useful.

Unknown's avatar

Revealed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2025], IT-Coach, IT-Guide, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments