-
-
Save rwilkes/554144882e89cf0f3c56f7b27f54998b to your computer and use it in GitHub Desktop.
PowerShell IIS Administration API demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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