Public/Connect-CustomerGraph.ps1
function Connect-CustomerGraph { [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$CustomerTenantId ) # Get SAM tokens if not already available begin { if (!$SAMTokens) { $SAMTokens = Get-SAMTokens } } # Generate a token for MS graph, and connect with it. process { try { $graphToken = New-PartnerAccessToken -ApplicationId $SAMTokens.ApplicationId -Credential $SAMTokens.ApplicationCredential -RefreshToken $SAMTokens.RefreshToken -Scopes 'https://graph.microsoft.com/.default' -ServicePrincipal -Tenant $CustomerTenantId } catch { Write-Error "Failed to generate a token for MS Graph: $_" } try { Connect-MgGraph -AccessToken ($graphToken.AccessToken | ConvertTo-SecureString -AsPlainText -Force) -NoWelcome } catch { Write-Error "Failed to connect to MS Graph: $_" } } } |