When sending the GET request to the server, which uses self-signed certificate:
add-type @\" using System.Net; using System.Security.Cryptography.X50
You could replace Invoke-WebRequest with Invoke-RestMethod which auto-converts json response to a psobject so you can use:
Invoke-WebRequest
Invoke-RestMethod
psobject
$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla" $response.flag