Skip to content

Instantly share code, notes, and snippets.

@jimmypc92
Last active January 23, 2023 19:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jimmypc92/00ba9644b3966fc58a13dad80a5c7ef1 to your computer and use it in GitHub Desktop.
Save jimmypc92/00ba9644b3966fc58a13dad80a5c7ef1 to your computer and use it in GitHub Desktop.
PowerShell IIS Administration API 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" }
# Make request, store psobject result
$response = Invoke-RestMethod -Method Get -Uri https://jimmyca-srv2.cloudapp.net:55539/api/webserver/websites -Headers $headers
# List websites
$response.websites
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment