Hi,
I'm new here and got some different code which is working. I have a rest call that provides and count - json like below. I would like to know how to get below into an variable. And also later to use this variable in the ScriptOut put status code.
REST API OUTPUT:
{"count":1883}
Code:
$website = $args[0];
$creds = Get-Credential ${creds}
$user = $creds.GetNetworkCredential().UserName
$pass = $creds.GetNetworkCredential().Password
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify endpoint uri
# Specify HTTP method
$method = "get"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
# Send HTTP request
$response =Invoke-RestMethod -Headers $headers -Method $method -Uri $website | select count
# Print response
return $response
if ($response -eq 1883) {
Write-Host "Equal"
}
else { Write-Host "NOT EQUAL"};
OUTPUT:
Output: ==============================================
count
-----
1883