Public/Complete-PegasusSyncOperation.ps1
function Complete-PegasusSyncOperation { [CmdletBinding(SupportsShouldProcess = $true)] Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $Operation ) Process { if ($PSCmdlet.ShouldProcess($Operation.Endpoint, $Operation.Method)) { Write-Verbose "Performing operation $($Operation.Method) $($Operation.Endpoint)" if ($Operation.Method -in "PATCH", "POST") { try { Invoke-PegasusRequest -Method $Operation.Method -Endpoint $Operation.Endpoint -InputObject $Operation.Body | Out-Null } catch { $msg = $_.ErrorDetails?.Message?.Trim()?.Trim("""") $json = ($Operation.Body ?? @{}) | ConvertTo-Json -Depth 10 -Compress Write-Error "Failed to perform operation $($Operation.Method) $($Operation.Endpoint) : $_ : $msg : $json" } } else { try { Invoke-PegasusRequest -Method $Operation.Method -Endpoint $Operation.Endpoint | Out-Null } catch { $msg = $_.ErrorDetails?.Message?.Trim()?.Trim("""") Write-Error "Failed to perform operation $($Operation.Method) $($Operation.Endpoint) : $_ : $msg" } } } } } |