From 5fade7c748ec9c5ad8750538dbb4de8209627c47 Mon Sep 17 00:00:00 2001 From: Leo D'Arcy Date: Fri, 29 Nov 2019 15:57:38 +0000 Subject: [PATCH] Added B2B support --- MSGraphFunctions/Public/Connect-Graph.ps1 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/MSGraphFunctions/Public/Connect-Graph.ps1 b/MSGraphFunctions/Public/Connect-Graph.ps1 index 4045245..17e2040 100644 --- a/MSGraphFunctions/Public/Connect-Graph.ps1 +++ b/MSGraphFunctions/Public/Connect-Graph.ps1 @@ -15,6 +15,8 @@ function Connect-Graph() { Administrator Consent for "Microsoft Intune PowerShell" permissions .PARAMETER ClientId ClientID of Azure AD Application with permissions for Microsoft Graph + .PARAMETER Tenant + Tenant Name or ID, by default the primary tenant is used, use this to specify the specify the required B2B tenant #> [cmdletbinding()] param( @@ -28,7 +30,10 @@ function Connect-Graph() { [bool]$AdminConsent = $false, [Parameter(Mandatory = $false)] - [string]$ClientId = "d1ddf0e4-d672-4dae-b554-9d5bdfd93547" + [string]$ClientId = "d1ddf0e4-d672-4dae-b554-9d5bdfd93547", + + [Parameter(Mandatory = $false)] + [string]$Tenant ) process { @@ -59,13 +64,18 @@ function Connect-Graph() { $null = [System.Reflection.Assembly]::LoadFrom($adal) $null = [System.Reflection.Assembly]::LoadFrom($adalForms) - if ($Credential) { - $tenant = (New-Object "System.Net.Mail.MailAddress" -ArgumentList $Credential.Username).Host - } - else { - $tenant = (New-Object "System.Net.Mail.MailAddress" -ArgumentList $Username).Host + if ([string]::IsNullOrEmpty($Tenant)) + { + if ($Credential) { + $tenant = (New-Object "System.Net.Mail.MailAddress" -ArgumentList $Credential.Username).Host + } + else { + $tenant = (New-Object "System.Net.Mail.MailAddress" -ArgumentList $Username).Host + } } + Write-Verbose "TenantID = $tenant" + $resourceAppIdUri = "https://graph.microsoft.com" $authority = "https://login.microsoftonline.com/$tenant"