Skip to content

Instantly share code, notes, and snippets.

@jimmyca15
Last active October 31, 2017 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyca15/06f16cacca549e3df62fe0f6cfdca282 to your computer and use it in GitHub Desktop.
Save jimmyca15/06f16cacca549e3df62fe0f6cfdca282 to your computer and use it in GitHub Desktop.
PowerShell IIS Administration monitoring demo
# Add type to handle the API certificate
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class ITrustACertificatePolicy : ICertificatePolicy {
public ITrustACertificatePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
X509Certificate2 apiCert = cert as X509Certificate2;
return apiCert == null ? false : apiCert.Thumbprint == "2D1604329438A9D9E4B4FB461C2BD3A336CEB1D8";
}
}
"@
# Check for api certificate for this session
[System.Net.ServicePointManager]::CertificatePolicy = new-object ITrustACertificatePolicy
# Set access token header
$headers = @{ "Access-Token" = "Bearer OgMks6N7CtZTptX2DTnLe8JvkmATOuqw1ZJnZzK1RojeYs251Wlfvg"; "accept" = "application/hal+json" }
# Make request, store psobject result
$response = Invoke-RestMethod -Method Get -Uri https://jimmyca-srv2.cloudapp.net:55539/api/webserver/monitoring -Headers $headers
# List websites
$response
# To view the entire object try:
# ConvertTo-Json $response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment