Skip to content

Instantly share code, notes, and snippets.

Sam-Martin / Test Kitchen Add Vagrant
Last active Mar 21, 2020
Test Kitchen VagrantFile.rb to add disks & test_helper.bash to format them
View Test Kitchen Add Vagrant

Use these two files to add disks to your VMs (here adding three disks) when Kitchen spins up Vagrant boxes.

  • test_helper.bash (add to your bats test with load test_helper)
  • vagrantfile.rb (add to your .kitchen.yml using)
  name: vagrant
      - vagrantfile.rb
Sam-Martin / generate-ami-hashtable-for-cloudformation.ps1
Created Apr 19, 2015
Generate AMI hashtable for cloudformation
View generate-ami-hashtable-for-cloudformation.ps1
# Ensure you amend this value to reflect the AMI you're interested in
$imageType = "Windows_Server-2012-R2_RTM-English-64Bit-Core"
$resultsArchitectureFirst = @{'64'=@();'32'=@()};
$resultsRegionFirst = @{};
# Loop through all regions and find the appropriate image
foreach($region in $(Get-AWSRegion).Region){
Sam-Martin / New-EC2VolumeSnapshotOffsite.psm1
Created Apr 19, 2015
Snapshot EBS Volume and copy snapshot to another region
View New-EC2VolumeSnapshotOffsite.psm1
Creates a snapshot of an EBS volume, copies it to the destination region, then deletes the snapshot (not the volume) in the source region
You will need to run either Set-AWSCredentials or Initialize-AWSDefaults passing your accesskey and privatekey prior to execution of this cmdlet in order to establish connectivity to AWS.
To set the default AWS credentials for your current Windows user, use:
Initialize-AWSDefaults -AccessKey ***** -SecretKey ***** -Region us-west-2
Naturally you will need to replace the asterisks and region with the values appropriate to your configuration
Sam-Martin / AWS-Check-Users-Without-MFA.ps1
Created Apr 19, 2015
PRTG check AWS users without MFA
View AWS-Check-Users-Without-MFA.ps1
# Grab the current working directory of the script for the purposes of loading the DLL
$scriptWorkingDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
View ServiceNow API Example in

Replace yourdomain with your service now URL. User must have the rest_service role.

Sam-Martin / Get-VMClusterContention.ps1
Last active Aug 29, 2015
Get VMWare Cluster Contention
View Get-VMClusterContention.ps1
foreach($cluster in Get-Cluster){
# Get host memory free
$vmHostObj = $cluster | Get-VMHost
$totalVMHostMemory = [int]$($vmHostObj | measure-object -property MemoryTotalGB -sum).sum;
$totalVMHostMemoryFree = $($vmHostObj | %{$_.MemoryTotalGB - $_.MemoryUsageGB} | measure-object -sum).sum;
$highestHostMemoryTotal = $($vmHostObj | sort-object -property MemoryTotalGB | select -last 1).MemoryTotalGB;
$totalVMHostCPU = [int]$($vmHostObj | measure-object -property CPUTotalMhz -sum).sum;
$totalVMHostCPUFree = $($vmHostObj | %{$_.CPUTotalMhz - $_.CPUUsageMhz} | measure-object -sum).sum;
$highestHostCPUTotal = $($vmHostObj | sort-object -property CPUTotalMhz | select -last 1).CPUTotalMhz;
Sam-Martin / Parse Default IIS log file.ps1
Created May 27, 2015
Parse default IIS log file in PowerShell
View Parse Default IIS log file.ps1
gc "iislogfile.log" | %{
$row = $_.split(' ')
New-Object psobject -Property @{
# date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken OriginalIPAddress
DateCreated = Get-Date ($row[0] + ' ' + $row[1])
"s-ip" = $row[2]
"cs-method" = $row[3]
"cs-uri-stem" = $row[4]
"cs-uri-query" = $row[5]
"s-port" = $row[6]
View Get-S3FolderLastModified.ps1
function Get-S3FolderLastModified {
Sam-Martin / Get-AWSBillingEstimate.ps1
Created Sep 8, 2015
Get AWS Billing Estimate by PowerShell cmdlets
View Get-AWSBillingEstimate.ps1
$Dimension1 = New-Object Amazon.CloudWatch.Model.Dimension
# Has to be us-east-1 irrespective of what regions you use
$result = Get-CWMetricStatistics -MetricName EstimatedCharges -region us-east-1 -Namespace "AWS/Billing" -StartTime (Get-Date).AddDays(-14) -EndTime (get-date) -Period (60*60*24) -Statistics 'Maximum' -Dimensions @($Dimension1, $Dimension2)
$result.Datapoints | select timestamp,maximum | sort timestamp