Het volgende voorbeeld geeft toegang tot de Uptrends API en haalt de lijst van Uptrends' controlestation locaties op.
# Specify your Uptrends login info here $user = "james@galacticresorts.com" $pass= "1234xxx" # URI to the API method you want to execute $uri = "https://api.uptrends.com/v3/checkpointservers" # Compile the login info into credentials containing basic authentication $passwordValue = ConvertTo-SecureString $pass -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ($user, $passwordValue) # Execute the request $result = Invoke-RestMethod -Uri $uri -Method Get -Credential $cred -Headers @{ Accept = "application/json" }
Dit laatste statement zet het resultaat in de `$result` variabele. U kunt dan verder werken met deze content. Bijvoorbeeld, om een IPv4 adres te achterhalen voor een bepaald controlestation:
$result | Where-Object { $_.CheckPointName -eq 'Leicester, United Kingdom' } | Select IPAddress