Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires -Version 7.2
- #Requires -Modules MSAL.PS, Microsoft.PowerShell.ConsoleGuiTools, ExchangeOnlineManagement
- $ErrorActionPreference = "stop"
- $PartnerAppId = "{CLIENT_ID}"
- $MsalParams = @{
- ClientId = $PartnerAppId;
- Interactive = $true;
- Scope = "https://api.partnercenter.microsoft.com/user_impersonation";
- }
- $PartnerAccessToken = Get-MsalToken @MsalParams
- $PartnerCustomersParams = @{
- Uri = "https://api.partnercenter.microsoft.com/v1/customers";
- Headers = @{
- "Authorization" = "Bearer $($PartnerAccessToken.AccessToken)"
- };
- Method = "Get";
- }
- # Use this cool module to select a single customer from the list.
- $Customer = (Invoke-RestMethod @PartnerCustomersParams).items | `
- Select-Object -ExpandProperty companyProfile | `
- Select-Object -Property companyName, tenantId | `
- Out-ConsoleGridView -OutputMode Single -Title "Select your tenant"
- # Get tokens for Exchange Online and Microsoft Graph
- $MsalCustomerGraphParams = @{
- ClientId = $PartnerAppId;
- TenantId = $Customer.tenantId;
- Scope = "Directory.Read.All"; # Change this depending on what you're doing below
- Silent = $true; # Uses the saved refresh token
- }
- $MsalCustomerEXOParams = @{
- ClientId = $PartnerAppId;
- TenantId = $Customer.tenantId;
- Scope = "https://outlook.office365.com/.default";
- Silent = $true; # Uses the saved refresh token
- }
- $CustomerGraphAccessToken = Get-MsalToken @MsalCustomerGraphParams
- $CustomerEXOAccessToken = Get-MsalToken @MsalCustomerEXOParams
- # Connect to Exchange Online and Microsoft Graph and run commands
- Connect-ExchangeOnline -DelegatedOrganization $Customer.tenantId -AccessToken $CustomerEXOAccessToken.AccessToken
- Connect-MgGraph -AccessToken $CustomerGraphAccessToken.AccessToken
- Get-MgUser
- Get-ExoMailbox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement