Notice; None of this is very advanced.. :)
-------------------
= VMware PowerCLI =
-------------------
find VMs based on IP
Get-VM * |where-object{$_.Guest.IPAddress -match "10.10.10.5"}
count number of powered on vms
Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | measure
create vlan, remember to adjust the options!!!!
Get-Cluster FuKluster | Get-VMHost | Get-VirtualSwitch -Name "vSwitch3" | New-VirtualPortGroup -Name "VLAN666-PirateServerGroup" -VLanId 666
unmount ALL cd's in the vcenter ;)
Get-VM * | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false
unmount ALL tools CDs in the vcenter.
Get-VM | Get-CDDrive | where{$_.IsoPath -match "vmware/isoimages"} | Set-CDDrive -NoMedia -Confirm:$false
list all snapshots and their vms powered on VMs
get-vm | get-snapshot | format-list
get cluster memory usage
Get-Cluster | Select Name,@{N="Memory used MB";E={ $_ | Get-VM | %{$_.ExtensionData.Summary.QuickStats.HostMemoryUsage} | Measure-Object -Sum | Select -ExpandProperty Sum}}
get cluster vm memory allocation
Get-Cluster | Select Name,@{N="Memory used MB";E={$_ | Get-VM | where-object {$_.PowerState -eq "PoweredOn" } | %{$_.MemoryMB} | Measure-Object -Sum | Select -ExpandProperty Sum}}
set advanced option on hosts
Get-VMHost | Set-VMHostAdvancedConfiguration Syslog.global.logDir -Value '[vsanDatastore] Logs'
get list of HA events
Get-VIEvent -MaxSamples 100000 -Start (Get-Date).AddDays(-1) -Type Warning | Where {$_.FullFormattedMessage -match "restarted"} |select CreatedTime,FullFormattedMessage | sort CreatedTime -Descending
get CPU overcommit ratio
((get-cluster RH |Get-VM | where {$_.PowerState -eq "PoweredOn"}|measure-object NumCPU -sum).sum/(get-cluster RH |get-vmhost | where {$_.ConnectionState -eq "Connected"} |measure-object NumCpu -sum).sum)
--------------
= PowerShell =
--------------
Get SQL server edition
$inst = (get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
foreach ($i in $inst)
{
$p = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL').$i
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Edition
(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$p\Setup").Version
}
------------------
= Linux (Debian) =
------------------
Delete all mails that match a domain in postfix queue
# for i in `mailq |grep spammerdomain.org|awk '{print $1}'|cut -d\* -f1`;do postsuper -d $i;done
Exact starttime of PID
# ps -o lstart= -p the-pid
If you need to remotely hard-reset your Linux system because of a read-only file system (or anything else), try Magic SysRq:
# echo 1 >/proc/sys/kernel/sysrq ; echo b >/proc/sysrq-trigger
Refresh scsi devices (eg. for adding a disk hot in a VM)
# for i in /sys/class/scsi_host/*;do echo "- - -" > $i/scan;done
Switch default editor in Debian to vim.tiny (eg. if you don't like shit fuck editor nano)
# update-alternatives --set editor /usr/bin/vim.tiny
Null route an IP for some reason ...
# route add -host 66.66.66.66 reject
Get public IP
# curl http://ipecho.net/plain
Disable historyfile, when being naughty
# export HISTFILE=/dev/null
Display size of files and folders in human readable...
# du -hs * | sort -h
Time to calculate PI with 5000 decimals (I get about 33sec on a "PM" with a E5420, about the same on a (vmware) VM running on a E5620)
# time echo "scale=5000; a(1)*4" | bc -l
List memory modules in Linux
# dmidecode -t 17 (or lshw)
Convert unixtime to readable..
# date -d @1278999698
Remove the first 5 characters on each line in a file
# sed -i 's/^.....//' shittyfile
Enable hot-added memory in Linux (under VMware)
# for i in `grep offline /sys/devices/system/memory/*/state|cut -d: -f1`;do echo online > $i;done
Check memory used by Apache (for tuning MaxRequestWorkers shite)
# ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}'
Mysql add index..
# ALTER TABLE `wp_postmeta` ADD INDEX wp_postmeta_index(`meta_key`);
-------
= VIM =
-------
Save a file you edited in vim without the needed permissions
:w !sudo tee %
-----------
= Windows =
-----------
Add route persistent
# route ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.2
Tail a logfile
# Get-Content myTestLog.log –Wait
# Get-Content myTestLog.log -wait | where { $_ -match “WARNING” }
---------------
= Media stuff =
---------------
Timelapse with mencoder (this example is for use with GoPro photos, files.txt should include a list of the frames, find . -name *JPG > files.txt)
# mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:vqscale=3:threads=4 -vf scale=1920:1080 -mf type=jpeg:fps=20 mf://@files.txt -o time-lapse.avi
Add embedded timestamp to GoPro files and crop them to 16:9
# convert originalfile.jpg -crop 4000x2250+0+200 -font fixed -pointsize 72 -fill red -annotate +3320+2400 %[exif:DateTimeOriginal] with_time/output.jpg