Base/Invoke-FGDeleteRequest.ps1
function Invoke-FGDeleteRequest { [alias("Invoke-DeleteRequest")] [cmdletbinding()] Param ( [Parameter(Mandatory = $true)] [string]$URI ) If (!($Global:AccessToken)) { Throw "No Access Token found. Please run Get-AccessToken or Get-AccessTokenInteractive before running this function." } Else { $AccessToken = $Global:AccessToken } If ($Global:DebugMode) { If ($Global:DebugMode.Contains('D')) { Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++ Debug Message ++++++++++++++++++++++++++++++++++++++++++++++++++++++++" -ForegroundColor Blue Write-Host "Invoke-FGDeleteRequest" -ForegroundColor Blue Write-Host $URI -ForegroundColor Blue } } #Check if Access token is expired, if so get new one. $TokenIsStillValid = Confirm-FGAccessTokenValidity if (!($TokenIsStillValid)) { If ($Global:DebugMode.Contains('G')) { Write-Host "Token Expired, getting new one" -ForegroundColor Blue } If ($global:ClientSecret) { Get-FGAccessToken -ClientID $Global:ClientID -TenantId $Global:TenantId -ClientSecret $global:ClientSecret } Else { Throw "Access Token expired." } } Try { #Run request $Result = Invoke-RestMethod -Method DELETE -Uri $URI -Headers @{"Authorization" = "Bearer $AccessToken" } } Catch { Throw $_ } if ($Result.PSobject.Properties.name -match "value") { $ReturnValue = $Result.value } else { $ReturnValue += $Result } return $ReturnValue } |