# basic information # role based access API [string]$publicApiSecret = 'Mrayu0uASFiMR_sXf1Lcsz9VJbZB3vsl9erban8yvMk' #url without https $baseUrl = 'loginenterprisetw.sandyshores.nl' # if something goes wrong (e.g. authentication) we stop processing this script $ErrorActionPreference = 'Stop' # WARNING: ignoring SSL/TLS certificate errors is a security risk $code = @" public class SSLHandler {public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler() {return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });} } "@ Add-Type -TypeDefinition $code # WARNING: ignoring SSL/TLS certificate errors is a security risk [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler() # this is only required for older version of PowerShell/.NET [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 # Define authorization header $Header = @{ "Accept" = "application/json" "Authorization" = "Bearer $publicApiSecret" } # Define body contents $Body = @{ "orderBy" = "Name" "direction" = "desc" "count" = "20" } #Parameters of the API command $Parameters = @{ Uri = 'https://' + $baseUrl + '/publicApi/v5/tests/' Headers = $Header Method = 'GET' body = $Body ContentType = 'application/json' } #request data with call to the public api environments URL $Results = Invoke-RestMethod @Parameters #display each environment in the results ForEach ($item in $Results.items) { Write-Host $item }