Skip to content

Instantly share code, notes, and snippets.

View jgard's full-sized avatar

Jesse Gardner jgard

View GitHub Profile
@jgard
jgard / Get-ADFSPEM.ps1
Created January 23, 2020 03:55
Extracts certificate information from ADFS hosted metadata, supplying it in two common formats- single line and multi-line PEM
Function Get-ADFSPEM ($ADFSHost) {
$key = ([xml](Invoke-WebRequest -UseBasicParsing -Uri "https://$ADFSHost/federationmetadata/2007-06/federationmetadata.xml").content).EntityDescriptor.Signature.KeyInfo.X509Data.X509Certificate
Write-Host "Single Line:" -ForegroundColor Green
write-host $key
write-host ""
Write-Host "Multi-Line PEM format:" -ForegroundColor Green
Write-Host "-----BEGIN CERTIFICATE-----"
0..[math]::Floor($key.Length/64) |%{
write-host ($key[($_*64)..(($_*64)+63)] -join '')
}
@jgard
jgard / Get-AWSServiceNamespaces.ps1
Last active November 5, 2019 18:40
Retrieves a list of AWS service namespaces/prefixes available for use in IAM policy, by scraping Amazon docs pages.
$WebRootURL='https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_actions-resources-contextkeys.html'
## Retrieve service information from AWS Documentation
$BaseURL = $WebRootURL -replace "[^/]*$"
$Links = Invoke-WebRequest -UseBasicParsing -Uri $WebRootURL | select -ExpandProperty links |?{$_.href -like "list_*" -and !($_.class)}
$i=0
$Links |%{
$i++
Write-Progress -Activity "Retrieving details AWS services" -Status "Service $i of $($Links.Count)" -CurrentOperation $_.href -PercentComplete (($i/($links.count))*100)
$ServiceMatch = Invoke-WebRequest -UseBasicParsing -Uri "${BaseURL}$($_.href)" | Select -ExpandProperty Content | Select-String '\<p\>(.*?) \(service prefix\: \<code class=\"code\"\>(.*?)\<\/code\>\)'
@jgard
jgard / Get-AWSTempCred.ps1
Last active January 12, 2022 00:23
Powershell: Get AWS temporary credentials via ADFS including support for RSA SecurID MFA
Function Get-AWSTempCred {
[CmdletBinding()]
param (
[string]$ADFSHost='adfs.domain.com', ##Change for environment-appropriate default if desired
[string]$RelyingParty = 'urn:amazon:webservices',
[pscredential]$Credential
)
$WebRequestParams=@{ #Initialize parameters object
Uri = "https://$ADFSHost/adfs/ls/IdpInitiatedSignon.aspx?LoginToRP=$RelyingParty"