Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions MSGraphFunctions/Public/Connect-Graph.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -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"

Expand Down