Skip to content

Instantly share code, notes, and snippets.

View lantrix's full-sized avatar
:octocat:
always coding and merging

Ted B lantrix

:octocat:
always coding and merging
View GitHub Profile
@lantrix
lantrix / sql_space.sql
Created September 16, 2014 07:36
database file size statistics
-- Copy of script from Jugal Shah
-- http://sqldbpool.com/2013/05/26/t-sql-script-to-find-out-the-database-file-size-space-used-and-available-free-space/
set nocount on
create table #dbfileInfo(
name varchar(300),
location varchar(300),
filesizeMB decimal(9,2),
spaceUsedMB decimal(9,2),
@lantrix
lantrix / instances_by_tags.ps1
Created September 18, 2014 05:41
Get all AWS instances in certain environment (by Tag) and show Name Tag
#get instances with specific tag and show
$tagFilter1 = New-Object Amazon.EC2.Model.Filter
$tagFilter1.Name = "tag:Environment Name"
$tagFilter1.Value.Add("Test")
$tagFilter2 = New-Object Amazon.EC2.Model.Filter
$tagFilter2.Name = "tag:Name"
$tagFilter2.Value.Add("*")
$instances = Get-EC2Instance -Filter @($tagFilter1,$tagFilter2)
foreach ($i in $instances.Instances) {
$i.InstanceId
@lantrix
lantrix / dynamic_variables.ps1
Created September 23, 2014 00:51
Powershell dynamic variables
$varsToSet = @("Something","Else","Here")
$i=0
#set variables
foreach ($this in $varsToSet) {
$i++
New-Variable -Name "dynamic$($this)" -Value $i
}
#retrieve variables
@lantrix
lantrix / tag_some_volumes.ps1
Created September 23, 2014 07:57
Tag a bunch of new volumes in AWS EC2
$newvols = ("vol-7f273b7b","vol-b5273bb1","vol-b6273bb2","vol-c6273bc2","vol-b1273bb5")
$tags = @()
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "Attached"
$tag.Value = "i-d7a706e9"
$tags += $tag
$tag = New-Object Amazon.EC2.Model.Tag
@lantrix
lantrix / vol_to_del.ps1
Created October 16, 2014 04:17
AWS volumes attached to instance to delete
#method 1
$f = New-Object Amazon.EC2.Model.Filter
$f.Name = "attachment.instance-id"
$f.Value.Add("i-a005239e")
$voltodel = Get-EC2Volume -Filters $f
#method 2
$voltodel = Get-EC2Volume -Filters @{Name="attachment.instance-id"; Value="i-a005239e"}
$disks = (wmic diskdrive list brief | measure-object -line | select -ExpandProperty Lines)-2
#1..
$disks | ForEach-Object -Begin {$a = $null} -Process { `
$a += $("select disk "+$_+[char][int](13)+[char][int](10)) ; `
$a += "online disk noerr "+[char][int](13)+[char][int](10) ; `
$a += "clean "+[char][int](13)+[char][int](10) ; `
$a += "attributes disk clear readonly noerr "+[char][int](13)+[char][int](10) ; `
$a += "convert dynamic noerr "+[char][int](13)+[char][int](10) ;} -End { $a += "exit"+[char][int](13)+[char][int](10) ; `
$a | Set-Content c:\diskpart1.txt -Encoding ASCII `
@lantrix
lantrix / create_striped_volume.ps1
Last active August 29, 2015 14:08
Create Striped Volume set from (Available) Raw Disks
#
# Create Striped Volume set from (Available) Raw Disks
#
#settings
$letter = "E" #Drive Letter
$allocation = 65536 #Blocksize in Bytes
$label = "My Disk Label" #drive label
#Get started
@lantrix
lantrix / create_single_dynamic_volume.ps1
Created October 23, 2014 06:20
Create Striped Volume set a Single (only 1 available) Raw Disk
#
# Create Striped Volume set a Single (only 1 available) Raw Disk
#
#settings
$letter = "F" #Drive Letter
$allocation = 65536 #Blocksize in Bytes
$label = "Master F: Logs" #drive label
#Get started
@lantrix
lantrix / _createVolumes.ps1
Last active August 29, 2015 14:08
AWS Instance Volume Creation Scripts
<#
.SYNOPSIS
Creates a number of NTFS Volume in AWS, attaches to an instance, formats, brings them online.
.EXAMPLE
_createVolumes.ps1 -zone ap-southeast-2a -type standard -instance i-12345678 -allocation 64
This command creates volumes for instance i-12345678.
The Disks will be 64KB NTFS allocation.
#>
#No params supplied
@lantrix
lantrix / newinstance.ps1
Last active August 29, 2015 14:08
Spin up an AWS test instance with powershell
#setup variables
$ami = "ami-e95c31d3" #public Windows server 2012 R2
$subnet = "subnet-e1a4f488" #VPC Subnet for instance
$group = "sg-e5f3e889" #whatever security group
$folder = 'C:\Users\me\OneDrive'
$allVolumesAvailable = $False
$readyCount = 0
$maxRetries = 20
$sleepBetweenChecks = 10
$Retries = 0