Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkxeer authored Aug 2, 2024
1 parent c5b3b90 commit 4c8c020
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Scripts/Others/Connect-SavedGraph.ps1
Original file line number Diff line number Diff line change
@@ -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 ""

0 comments on commit 4c8c020

Please sign in to comment.