Skip to content

Instantly share code, notes, and snippets.

View tylergohl's full-sized avatar
😴

Tyler Gohl tylergohl

😴
View GitHub Profile
# Invoke using following syntax into IE:
# http://boxstarter.org/package/url?[raw link to this gist]
# Boxstarter options
$Boxstarter.RebootOk=$true
$Boxstarter.NoPassword=$false # Is this a machine with no logon password?
$Boxstarter.AutoLogin=$true
Set-WindowsExplorerOptions -EnableShowFileExtensions
Disable-UAC
$rgs = get-azurermresourcegroup | where-object { $_.ResourceGroupName -like "test??" }
ForEach ($rg in $rgs) {
$tags = $rg.Tags
$tags += @{Name="AutoShutdownSchedule";Value="1am -> 1pm, Saturday, Sunday"}
$rg | Set-AzureRmResourceGroup -Tag $tags
}
@tylergohl
tylergohl / UpdateAzureRMTags.ps1
Last active February 10, 2017 04:52
Updates Azure RM VM tags in bulk. Retain current tags.
$TestVMs = Get-AzureRMVM | where ResourceGroupName -like test*
ForEach ($VM in $TestVMs) {
$CurrentTags = $VM.Tags
Write-Verbose "VM name: $VM.Name"
Write-Verbose "Current tags: $CurrentTags"
$VM | Update-AzureRMVm -tags ($CurrentTags += @{yournewtag="yournewvalue"}) -ErrorAction Continue
}
# For auditing when updates were installed, useful for SOC 2
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object Title, Description, Date,
@{name="Operation"; expression={switch($_.operation) {
@tylergohl
tylergohl / Run-SSMCommand.ps1
Created July 6, 2018 13:23
Runs a ec2 systems manager command
$NameWildcard = 'prd01worker*'
$Comment = 'Doing stuff'
$Commands = @(
'dir c:\users',
'dir c:\'
)
# Instance state code 16 is for powered on instances
$Instances = (Get-EC2Instance -Filter @( @{name='tag:Name'; values=$NameWildcard}; @{name='instance-state-code'; values = 16} ) | Select-Object -ExpandProperty instances).InstanceId
# Find automation runs that have happened in the last 24 hours and the instances that they have run against
$Instances = (Get-SSMAutomationExecutionList | where-object { $_.DocumentName -like '*ssm-nightlyrecycle-doc*' -and $_.ExecutionStartTime -gt (Get-Date).AddHours(-24) } | Get-SSMAutomationExecution).Parameters
$InstanceIDs = ((Get-SSMAutomationExecutionList | where-object { $_.DocumentName -like '*ssm-nightlyrecycle-doc*' -and $_.ExecutionStartTime -gt (Get-Date).AddHours(-24) } | Get-SSMAutomationExecution).Parameters).Values
$Instances = ($InstanceIDs | Get-EC2Instance | Select-object -ExpandProperty Instances)
(($Instances.tag) | Where-Object Key -eq "Name").value
@tylergohl
tylergohl / FixDumbTagMistake.ps1
Created September 26, 2018 14:58
Sometimes you gotta break all your AWS tags
# Change up $role / $product as needed
$MajorEnv = 'int'
$EnvNumber = '01'
$Env = "$MajorEnv$EnvNumber"
$Role = 'es-master'
$values = "$Env-$Role*"
$Product = 'los'
# Get empty web server tags
DMZSubnetA:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Select ['0', !GetAZs {Ref: 'AWS::Region'}]
VpcId: !Ref 'EnvironmentVpc'
MapPublicIpOnLaunch: Yes
CidrBlock: !Ref 'DMZSubnetCidrA'
Tags:
- Key: Name
Value: !Sub "${EnvironmentValue}-dmzsubnet-a"