PrivateFunctions/Remove-Entity.ps1
Function Remove-Entity { [OutputType([Bool])] [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [ValidateNotNull()] [Int] $EntityId ) Validate-Context Write-Verbose "Verwijderen van entiteit met Id '$($EntityId)'..." Try { $Response = Invoke-WebRequest -UseBasicParsing -Uri "$($DqContext.GetEntityControllerUrl())/$($EntityId)" -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 entiteit met id '$($EntityId)': '$($_.Exception.Message)'." If ($ResponseBody -and $ResponseBody.Message) { $ErrorMessage = $ErrorMessage + [char]10 + [char]13 + " + DetailedMessage: $($ResponseBody.Message)" } Write-Error $ErrorMessage Return $False } } |