Skip to content

Instantly share code, notes, and snippets.

View jeffgreenca's full-sized avatar

jeffg jeffgreenca

  • Greater Seattle Area, WA
View GitHub Profile
#Quick & Dirty snapshot list
get-vm | % { $s = $_ | Get-Snapshot; if ($s) { write-output "VM: $($_.name), Snap: $($s.name)" } }
@jeffgreenca
jeffgreenca / compare-vcenter-roles.ps1
Created May 10, 2016 18:03
Compare specific privileges assigned to roles with matching names in two different vCenters
#Compare specific privileges assigned to roles with matching names in two different vCenters
#Populate two arrays with roles from old vCenter 5.5 and new vCenter 6.0
Connect-VIServer oldvcenter
$p_old = Get-VIRole
Disconnect-VIServer
Connect-VIServer
$p_new = Get-VIRole
Disconnect-VIServer
@jeffgreenca
jeffgreenca / add-swap-files.sh
Created April 27, 2016 21:23
Add a swap file Linux
#!/bin/sh
echo "Current Memory Configuration"
free -m
read -p "Continue or ctrl-c? "
echo "Disk Free Space"
df -h
read -p "Make 4GB swap file at /swapfile? Continue or ctrl-c..."
echo "Allocating space..."
fallocate -l 4G /swapfile
echo "Formatting as swap..."
#/bin/sh
#List all listening ports and their bound IP
ss -lntu | awk '{print $5}' | awk -F ':' '{print $2, "(", $1, ")" }' | sort -n
#Lists just the ports
#ss -lntu | awk '{print $5}' | sed 's/^.*://' | sort -n
@jeffgreenca
jeffgreenca / start-ssh.ps1
Created April 15, 2016 17:34
Start SSH using PowerCLI
get-vmhost | % { start-vmhostservice -hostservice ($_ | Get-VMHostService | ? key -eq "TSM-SSH") }
#Get VM Host Max EVC Mode
get-view -viewtype hostsystem | select name, {$_.parent}, {$_.Summary.MaxEVCModeKey} | sort "`$_.parent"
#vmotion-validation-test.ps1
#vMotion a VM over all hosts in a cluster, twice.
$cluster = Read-Host "Cluster Name"
$vm = Read-Host "Test VM Name"
function validate-vmotion($cluster, $vm) {
$totalms = 0
$count = 0
get-cluster $cluster | get-vmhost | foreach {
$duration = Measure-Command {
@jeffgreenca
jeffgreenca / get-vm-recent-reconfigurations.ps1
Created March 17, 2016 14:43
Get details on VM reconfiguration from Get-VIEvents
#ajz posted this example at https://www.reddit.com/r/vmware/comments/4akx3o/when_did_somebody_change_the_memory/d126zrc
#Saving here for future reference
# Get VM's "Reconfiguration" events
$changeevents = $vm | Get-VIEvent | Where { $_.FullFormattedMessage -like "Reconfigured*"}
# Who initiated the event
$changeevents[0].UserName
# What specs were changed
$changeevents[0].ConfigSpec
#given source.csv
#mac,ip
#aabbccddeef0,172.16.1.20
#aabbccddeef1,172.16.1.21
Import-CSV source.csv | % { Add-DhcpServerv4Reservation -Scope 172.16.1.0 -ClientID $_.mac -IPAddress $_.ip }
Get-Datastore | % { $sum = ($_ | get-vm | Measure-Object).count; echo "$($_.name), $sum" }