Skip to content

Instantly share code, notes, and snippets.

View Sam-Martin's full-sized avatar

Sam Martin Sam-Martin

View GitHub Profile
@Sam-Martin
Sam-Martin / install-chef.ps1
Created February 22, 2018 15:55
Install Chef Windows
if(test-path C:\chef\){
Write-Host "C:\chef exists!"
Start-Sleep -Seconds 3600
}
Set-ExecutionPolicy unrestricted -force
$VerbosePreference = 'continue'
$InstallPS1 = "https://omnitruck.chef.io/install.ps1"
$InstallPS1LocalPath = "$env:temp\install-chef.ps1"
$orgName = 'CHEF ORG NAME'
$ChefPackageUri = 'https://packages.chef.io/files/stable/chef/12.21.31/windows/2012r2/chef-client-12.21.31-1-x64.msi'
@Sam-Martin
Sam-Martin / zabbix-grafana-alerts.json
Last active March 5, 2018 15:09
Zabbix Grafana Alerts
{
"annotations": {
"list": [
{
"$$hashKey": "object:1373",
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
@Sam-Martin
Sam-Martin / update-zabbix-host-proxy.py
Created February 14, 2018 12:48
Update Zabbix hosts to report to proxies based on IPs
from pyzabbix import ZabbixAPI
import os
import json
import logging, sys
from pprint import pprint
#
#
# WARNING
# THIS
@Sam-Martin
Sam-Martin / Lambda Delete Test Kitchen Instances after 24hrs.py
Last active November 27, 2017 16:15
Lambda Delete Test Kitchen Instances after 24hrs
import boto3
from datetime import datetime
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
@Sam-Martin
Sam-Martin / Remove-OldbeatsIndices.ps1
Created November 23, 2017 10:14
Remove-OldbeatsIndices.ps1
$ElasticSearchURL = 'https://<elasticsearchurl>:<port>'
$indices = (iwr "$ElasticSearchURL/_cat/indices?format=json&pretty").content | ConvertFrom-Json
$indices.Index | ?{$_ -match '\d{4}\.\d\d\.\d\d$'} | sort
$IndicesWithDate = $indices | ?{$_.index -like '*beat-*'} | select index,@{L="Date";E={get-date ($_.index -split '-')[1]}}
$indicesToDelete = $IndicesWithDate | ?{$_.date -lt (Get-Date).AddDays(-7)}
foreach($index in $indicesToDelete){
$index.index
iwr "$ElasticSearchURL/$($index.index)" -Method delete
@Sam-Martin
Sam-Martin / Get-CPUUtilisationAllInstancesMultipleAccounts.ps1
Created November 14, 2017 14:05
Get-CPUUtilisationAllInstancesMultipleAccounts.ps1
$ProfileNames = @(
"Profile1",
"Profile2"
)
foreach($Profile in $ProfileNames){
Set-AWSCredential -ProfileName $Profile
$StartTime = (Get-Date).AddDays(-30)
$EndTime = (Get-Date)
@Sam-Martin
Sam-Martin / Copy-RecentSnapshotsToNewRegion.ps1
Last active September 14, 2017 13:49
Copy All snapshot for the last 24hrs to another region
$Env:AWSAccountID = "ACCOUNTID"
$Env:SourceRegion = "eu-central-1"
$ENV:DestinationRegion = "eu-west-1"
$env:AgeOfSnapshotsDays=1
$SourceSnapshots = Get-EC2Snapshot -region $Env:SourceRegion -OwnerId $Env:AWSAccountID
$SourceFiltered = $SourceSnapshots | ?{$_.starttime -gt (get-date).AddDays(-1*$env:AgeOfSnapshotsDays)}
Write-Verbose "Found $($SourceFiltered.count) snapshots to copy from $Env:SourceRegion to $Env:DestinationRegion"
@Sam-Martin
Sam-Martin / gist:9f6bba63785fd3071882c6c313210520
Created August 8, 2017 12:35
PowerShell rename and join computer to computer
Rename-Computer -NewName $newComputerName
Add-Computer -Credential $Credentials -DomainName 'SDLPRODUCTS.com' -Force -Options JoinWithNewName,AccountCreate
@Sam-Martin
Sam-Martin / Colour-output.ps1
Created July 18, 2017 07:48
PowerShell Coloured output (stolen from someone somewhere)
function Format-AnsiColor {
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[AllowEmptyString()]
[String]
@Sam-Martin
Sam-Martin / add-winrm.ps1
Created July 5, 2017 14:11
Add WinRM to all SecurityGroups that have RDP
$Ips = @("192.168.1.1")
foreach($Region in $(Get-AWSRegion).Region){
$SecurityGroupsContainingRDP = Get-EC2SecurityGroup -region $Region| ?{$_.ippermission.FromPort -eq 3389}
Foreach($SecurityGroup in $SecurityGroupsContainingRDP){
Write-Verbose "Adding WinRM to $($SecurityGroup.GroupID)"
try{
Grant-EC2SecurityGroupIngress -GroupId $SecurityGroup.GroupId -region $Region -IpPermission @{IpProtocol="TCP";FromPort=5985;ToPort=5986;IPRanges=$IPs}
}catch{
if($_.exception.message -like "*already exists*"){
Write-Verbose "`tRule already exists"