Skip to content

Commit 4c8c020

Browse files
authored
Add files via upload
1 parent c5b3b90 commit 4c8c020

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Scripts/Others/Connect-SavedGraph.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Connect-To-Graph {
2+
param (
3+
[string]$TenantId,
4+
[string]$ClientId,
5+
[string]$ClientSecret
6+
)
7+
8+
Write-Host " "
9+
Write-Host "Connecting to Microsoft Graph with the provided credentials..." -ForegroundColor Yellow
10+
Start-Sleep -Seconds 1
11+
12+
try {
13+
$ClientSecretPass = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force
14+
$ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClientId, $ClientSecretPass
15+
Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential -NoWelcome
16+
17+
# Verify the connection
18+
$me = Get-MgUser
19+
Write-Host " "
20+
Write-Host "Successfully connected to Microsoft Graph!" -ForegroundColor Green
21+
return $true
22+
}
23+
catch {
24+
Write-Host " "
25+
Write-Host "ERROR: An error occurred while connecting to Microsoft Graph..." -ForegroundColor Red
26+
Write-Host "Error details: $_" -ForegroundColor Red
27+
Write-Host " "
28+
return $false
29+
}
30+
}
31+
32+
$connected = Connect-To-Graph -TenantId "" -ClientId "" -ClientSecret ""

0 commit comments

Comments
 (0)