Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Pearce austoonz

View GitHub Profile
@austoonz
austoonz / Get-AWSCommandsFromFile.ps1
Created Feb 14, 2020
This function will use the PowerShell Parser, and the Get-AWSCmdletName cmdlet (found in AWS.Tools.Common, AWSPowerShell or AWSPowerShell.NetCore) to find and output all AWS Cmdlets from a script. This can be used to assist with migrations to the AW
View Get-AWSCommandsFromFile.ps1
function Get-AWSCommandsFromFile {
[CmdletBinding()]
param (
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
$FilePath
)
$awsCommands = @{}
$tokens = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $FilePath -Raw), [ref]$null)
View Windows10-1809-RAST
# Get a list of RSAT Capabilities
Get-WindowsCapability -Name RSAT* -Online | Select-Object -Property DisplayName, State
# Install RSAT
Get-WindowsCapability -Name RSAT* -Online | Add-WindowsCapability -Online
@austoonz
austoonz / Invoke-FastPing
Last active Mar 1, 2019
A PowerShell Function that uses asynchronous ping commands to quickly ping a fleet of target machines.
View Invoke-FastPing
# This has been replaced by the FastPing PowerShell Module.
## Source
[GitHub](]https://github.com/austoonz/FastPing)
## Installation
```powershell
Install-Module -Name FastPing -Scope CurrentUser
@austoonz
austoonz / AWS-ApplyDSCMofs
Last active Sep 6, 2020
Samples for deploying an AWS Systems Manager Association using the 'AWS-ApplyDSCMofs' Document.
View AWS-ApplyDSCMofs
# Overview
This Gist provides samples to simplify the usage of the AWS Systems Manager Document, "AWS-ApplyDSCMofs".
@austoonz
austoonz / SSMAssociation
Created Feb 6, 2019
A CloudFormation template to create a PowerShell based AWS Systems Manager Association with inline PowerShell.
View SSMAssociation
---
AWSTemplateFormatVersion: '2010-09-09'
Description: "Systems Manager Association"
Resources:
Association:
Type: AWS::SSM::Association
Properties:
@austoonz
austoonz / Create-SSMAssociation
Created Feb 6, 2019
This scriptblock will create or update an AWS Systems Manager association
View Create-SSMAssociation
$ProfileName = ''
$AWSRegion = 'us-west-2'
$AssociationName = 'MyAssociationName'
$ComplianceSeverity = [Amazon.SimpleSystemsManagement.AssociationComplianceSeverity]::MEDIUM
$MaxConcurrency = '10%'
$MaxError = '5%'
$ExecutionTimeoutInSeconds = '300'
$ScheduleExpression = 'rate(1 hour)'
@austoonz
austoonz / Get-SecondsSinceEpoch
Created Jan 31, 2019
PowerShell snippet to retrieve the number of seconds since epoch ('01-01-1970')
View Get-SecondsSinceEpoch
function Get-SecondsSinceEpoch
{
param
(
[DateTime] $DateTime
)
if ($DateTime)
{
([DateTimeOFfset]$Date).ToUnixTimeSeconds()
@austoonz
austoonz / Get-AWSRegionLatency
Last active Jun 13, 2019
Sample PowerShell function to identify the closest AWS Region using AWS Service Endpoints.
View Get-AWSRegionLatency
function Get-AWSRegionLatency
{
param
(
[ValidateSet('dynamodb')]
[String] $ServiceForMeasurement = 'dynamodb'
)
$endpoints = [System.Collections.ArrayList]::new()
foreach ($region in (Get-AWSRegion).Region)
@austoonz
austoonz / get-arm64-ami-ids
Created Jan 25, 2019
Sample code for retrieving the AWS AMI IDs for ARM64 images.
View get-arm64-ami-ids
aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/arm64/recommended
@austoonz
austoonz / Write-SSMInventoryExample
Created Jan 25, 2019
Sample code for writing an AWS Systems Manager Inventory record.
View Write-SSMInventoryExample
$powerShellModules = Get-Module -ListAvailable
$date = Get-Date -UFormat '+%Y-%m-%dT%H:%M:%SZ'
$inventoryItems = [System.Collections.Generic.List[Amazon.SimpleSystemsManagement.Model.InventoryItem]]::new()
$contentList = [System.Collections.Generic.List[System.Collections.Generic.Dictionary[System.String,System.String]]]::new()
foreach ($moduleName in ($powerShellModules | Select-Object -Property Name -Unique).Name)
{
$module = $powerShellModules.Where({$_.Name -eq $moduleName}) | Sort-Object -Property Version -Descending | Select-Object -First 1
$contentDictionary = [System.Collections.Generic.Dictionary[System.String,System.String]]::new()