File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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 " "
You can’t perform that action at this time.
0 commit comments