PrivateFunctions/Remove-Check.ps1
Function Remove-Check { [OutputType([Bool])] [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [ValidateNotNull()] [Int] $CheckId ) Validate-Context Write-Verbose "Verwijderen van controle met Id '$($CheckId)'..." Try { $Response = Invoke-WebRequest -UseBasicParsing -Uri "$($DqContext.GetCheckControllerUrl())/$($CheckId)" -Method Delete -Header $DqContext.Headers Return $True } Catch [System.Net.WebException] { $Stream = $_.Exception.Response.GetResponseStream() $StreamReader = New-Object System.IO.StreamReader($Stream) $StreamReader.BaseStream.Position = 0 $ResponseBody = $StreamReader.ReadToEnd() $ResponseBody = $ResponseBody | ConvertFrom-Json -ErrorAction SilentlyContinue $StreamReader.Close() $ErrorMessage = "Fout bij verwijderen van controle met id '$($CheckId)': '$($_.Exception.Message)'." If ($ResponseBody -and $ResponseBody.Message) { $ErrorMessage = $ErrorMessage + [char]10 + [char]13 + " + DetailedMessage: $($ResponseBody.Message)" } Write-Error $ErrorMessage Return $False } } |