From 4c8c020217faed7749f6d2c99ae8cbc845fe496d Mon Sep 17 00:00:00 2001 From: Ikkxeer <137718457+ikkxeer@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:23:26 +0200 Subject: [PATCH] Add files via upload --- Scripts/Others/Connect-SavedGraph.ps1 | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Scripts/Others/Connect-SavedGraph.ps1 diff --git a/Scripts/Others/Connect-SavedGraph.ps1 b/Scripts/Others/Connect-SavedGraph.ps1 new file mode 100644 index 0000000..f58ca19 --- /dev/null +++ b/Scripts/Others/Connect-SavedGraph.ps1 @@ -0,0 +1,32 @@ +function Connect-To-Graph { + param ( + [string]$TenantId, + [string]$ClientId, + [string]$ClientSecret + ) + + Write-Host " " + Write-Host "Connecting to Microsoft Graph with the provided credentials..." -ForegroundColor Yellow + Start-Sleep -Seconds 1 + + try { + $ClientSecretPass = ConvertTo-SecureString -String $ClientSecret -AsPlainText -Force + $ClientSecretCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ClientId, $ClientSecretPass + Connect-MgGraph -TenantId $TenantId -ClientSecretCredential $ClientSecretCredential -NoWelcome + + # Verify the connection + $me = Get-MgUser + Write-Host " " + Write-Host "Successfully connected to Microsoft Graph!" -ForegroundColor Green + return $true + } + catch { + Write-Host " " + Write-Host "ERROR: An error occurred while connecting to Microsoft Graph..." -ForegroundColor Red + Write-Host "Error details: $_" -ForegroundColor Red + Write-Host " " + return $false + } +} + +$connected = Connect-To-Graph -TenantId "" -ClientId "" -ClientSecret "" \ No newline at end of file