Cheat Sheets 101

Reading Time: 8 minutes

Here you will find my collection of cheatsheets. This is mainly because I find it hard to remember every command. So i make a note here and refer back to it when needed.

If you like it please leave a comment, or if you have a command to recommend then please let me know.

VMware Cheat Sheet

Cheatsheets, Cheat Sheets 101

These cheat sheets are to be used on the VMware platform. Some commands require PowerCLI, others can be run directly on the Photon OS.

CommandWhat it does
/etc/init.d/hostd restart
/etc/init.d/vpxa restart
Restart VMWare Management services on Host
# Check if your VM has (Change Block Tracking) enabled or not
(Get-VM -Name Server_Name).ExtensionData.Config.ChangeTrackingEnabled
(Get-VM-Name Server_Name).ExtensionData.Config.ChangeTrackingEnabled
# Find VMs where CBT (Change Block Tracking) is Enabled
Get-VM| Where-Object{$_.ExtensionData.Config.ChangeTrackingEnabled-eq $true}
Check if Change Block Tracking enabled on VM
Get-VM | Get-NetworkAdapter | Select @{N=’VM’;E={$_.Parent.Name}},@{N=’AdapterName’;E={$_.Name}},@{N=’Type’;E={$_.Type}} | Where-Object{$_.Type -eq “e1000”}Get VM NIC with E1000
Get-vm | Select Name, @{N=”IP Address”;E={@($_.guest.IPAddress[0])}}Get VM IP
Get-VM | Select Name, @{N=”Cluster”;E={Get-Cluster -VM $_}}, @{N=”ESX Host”;E={Get-VMHost -VM $_}}, @{N=”Datastore”;E={Get-Datastore -VM $_}} |sort-object DatastoreGet VM Name, cluster, ESX , Datastore – and sort by Datastore
Get-VM | Get-NetworkAdapter | Select-Object Parent,TypeQuery the nic type of all virtual machines
get-vm | foreach-object -process {get-harddisk $_} | select-object storageformat | format-listQuery the disk type of all virtual machines
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-90)} | Select-Object VM, Name, Created, SizeMBGet snapshots older than 3 months
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-120)} | Remove-Snapshot -Confirm:$falseGet snapshots then remove them
Get-VM | Format-Table Name, @{Label=”NumSnapshots”;Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}Count number of snapshots
get-vm |% { get-view $ } | select Name, @{ Name=”;ToolsVersion”;; Expression={$}}Get Vmware tools version
get-vmhost | select Name,@{Name=”Time”;Expression={(get-view $_.ExtensionData.configManager.DateTimeSystem).QueryDateTime()}}Get time off hosts
ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N=”Name”;E={$VM.Name}},DiskPath, @{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}Get Vms and free disk space
Get-VMHost | Sort Name | Get-View | Select Name, @{N=”CPU”;E={$_.Hardware.CpuPkg[0].Description}}Get Host CPU info
Get-Vmhost *Lists Vmhost 
 get-vmhost -datastore Datastore_NameGet Vmhosts on particular datastore
$esxihost | Get-VMHostServiceGet Vmhosts services
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”}Find $vmhosts with SSH running
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Start-VMHostServiceStart SSH service on $exsihost
$esxihost | Get-VMHostService | where {$_.key -eq “TSM-SSH”} | Stop-VMHostServiceStop SSH service on $esxihost
Get-VM | Get-View | Select-Object Name, @{name=”toolsVersions”; Expression={$}}Get Vmware Tools versions
$esxihost | Get-VM | Get-SnapshotGet list of snapshots on $esxihost
$esxihost | Get-VM | Get-VMGuest | format-tableGet list of Guest Operating systems on $esxihost
get-vmhost | select Name,@{Name=”Time”;Expression={(get-view $_.ExtensionData.configManager.DateTimeSystem).QueryDateTime()}}Get time on all hosts
$esxihost |Get-VM |Where {$_.PowerState -eq “PoweredOn“} |Sort Name |Select Name, NumCPU, @{N=“OSHAL“;E={(Get-WmiObject -ComputerName $_.Name-Query “SELECT * FROM Win32_PnPEntity where ClassGuid = ‘{4D36E966-E325-11CE-BFC1-08002BE10318}’“ |Select Name).Name}}, @{N=“OperatingSystem“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select Caption).Caption}}, @{N=“ServicePack“;E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem |Select CSDVersion).CSDVersion}}Get Detailed VM information
 Get-VMHost | Select @{N=”Cluster”;E={Get-Cluster -VMHost $_}}, Name, @{N=”NumVM”;E={($_ | Get-VM).Count}} | Sort Cluster, NameList how many VMs are running on a Host
ForEach ($VM in Get-VM ){($VM.Extensiondata.Guest.Disk | Select @{N=”Name”;E={$VM.Name}},DiskPath, @{N=”Capacity(MB)”;E={[math]::Round($_.Capacity/ 1MB)}}, @{N=”Free Space(MB)”;E={[math]::Round($_.FreeSpace / 1MB)}}, @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}})}List all VM’s and their disk sizes
Get-VMHost | Sort Name | Get-View | Select Name, @{N=”CPU”;E={$_.Hardware.CpuPkg[0].Description}}Get Host CPU details
Get-VMHost |Sort Name |Get-View |Select Name, @{N=“Type“;E={$_.Hardware.SystemInfo.Vendor+ “ “ + $_.Hardware.SystemInfo.Model}},@{N=“CPU“;E={“PROC:“ + $_.Hardware.CpuInfo.NumCpuPackages + “ CORES:“ + $_.Hardware.CpuInfo.NumCpuCores + “ MHZ: “ + [math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}},@{N=“MEM“;E={“” + [math]::round($_.Hardware.MemorySize / 1GB, 0) + “ GB“}} Get Host Hardware information
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.ManagementTrafficEnabled} | Select Hostname, PortGroupName, IP, SubnetMaskThis will then dump the ESXi Hostnames, IPs and Subnets – For the Management Network
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.vMotionEnabled} | Select Hostname, PortGroupName, IP, SubnetMaskThis will then dump the ESXi Hostnames, IPs and Subnets – For the vMotion Network
Get-VMHost | Get-Cluster | Select Name, DrsEnabled, DrsMode, DrsAutomationLevelDump DRS status
Get-VMHost | Get-Cluster | Select Name, VMSwapfilePolicyDump VMSwapfilePolilcy
Get-VMHost | Get-Cluster | Select Name, HAAdmissionControlEnabledCheck status of HA Admission Control
Get-VMHost | Get-Cluster | Select Name, HAFailoverLevel, HARestartPriority, HAIsolationResponseCheck HA Status Levels
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select Hostname, PortGroupName, IP, MTUCheck for MTU Mismatches
Get-VirtualSwitch | Select VMHost, Name, MTUShows what the MTU settings on the Virtual Switches are
Get-VMGuestNetworkInterface –VM VMNAME | Select VM, IP, SubnetMask, DefaultGateway, DnsDumps a hosts Name, IP, Subnet, Gateway and DNS configuration 
Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicyThis will dump the Multipath Policy of the storage on the systems to determine what the MP configuration is. 
Get-VMHost | Sort Name | Select Name, @{N=”NTP”;E={Get-VMHostNtpServer $_}}This will dump NTP Configuration settings
Get-View -ViewType HostSystem | Sort Name | Select Name,@{N=”BIOS version”;E={$_.Hardware.BiosInfo.BiosVersion}}, @{N=”BIOS date”;E={$_.Hardware.BiosInfo.releaseDate}}This will dump the hosts BIOS version and date(s)
get-vmhost | Get-VMHostAdvancedConfiguration -Name the current SYSLOG Configuration
 $esxihost | Get-VM | Get-NetworkAdapter | Select @{N=’VM’;E={$_.Parent.Name}},@{N=’AdapterName’;E={$_.Name}},@{N=’Type’;E={$_.Type}} | Where-Object{$_.Type -eq “e1000”}Detailed E1000 details of $esxihost
Get-VIEvent -maxsamples 10000 |where {$_.Gettype().Name-eq “VmCreatedEvent” -or $_.Gettype().Name-eq “VmBeingClonedEvent” -or $_.Gettype().Name-eq “VmBeingDeployedEvent”} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage -First 10Find Vm’s Created last 10 days
$esxihost | Get-VM | Get-Snapshot | Select VM,Name,Created,sizegb,descriptionGet Snapshot details of $esxihost and list name, vmname, sizegb and snapshot description
$myvm | Get-NetworkAdapter | Select parent, name, type, networkname, connectionstate |Format-Table -AutoSizeDefine $myvms – lists network adapter details

PowerShell Cheatsheet

Cheatsheets, Cheat Sheets 101

If you need to install PowerShell, check out this post here.

Want more PowerShell One-Liners – check here.

CommandWhat it Does?
$psversiontableWhich version of powershell and I running
Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassAllow execution of commands
Get-Printer | select Name, DriverName, PortName | Export-Csv Printers.csv -NoTypeInformationList printers on a server
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize >C:\temp\installed.txtList installed programs on server
Get-ADDomainController -Filter * | Format-table name,domain, forest,site, ipv4address, operatingsystemFind Domain Controllers
Get-Childitem -Path C:\windows -Recurse -Filter *.dllFind any *dll* on filesystem – recursive
 Get-ItemProperty .\install.xml | select *Get Detailed File information
Search-ADAccount -LockedOut | Format-Table name,lastlogondate, lockedout, objectclass, passwordexpired, passwordneverexpiresFind locked out users
Search-ADAccount -AccountDisabled -UsersOnly | FT Name,ObjectClass -AFind disabled users
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly  | FT Name,ObjectClass -AFind Users not logged in for 90 days
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |Sort-Object | FT Name,ObjectClass -AFind Users not logged in for 90 days & Sort
Search-ADAccount -AccountInactive -TimeSpan 90.00:00:00 -UsersOnly |Sort-Object -property lastlogondate | FT Name,ObjectClass,lastlogondate, lockedout,  -AFind Users not logged in for 90 days & Sort by last logon 
Get-ADGroupMember -identity “Domain Admins” -recursive | select name | Export-csv -path C:\temp\Groupmembers.csv -NoTypeInformationFind “domain admins”
Get-ADComputer -Filter ‘Name -like “gbsyn*”‘ -Properties canonicalName,CN,created,IPv4Address,objectclass,OperatingSystem,OperatingSystemServicePackFind Computer with GBSYN* in the name
Get-ADPrincipalGroupMembership -identity ssi_rbailey | Sort-object | FT -property name, samaccountname -AutoSizeFind which AD groups a user is member of
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select DistinguishedName,Enabled | Export-Csv c:\temp\result.csv -NoTypeInformationFind Disabled Domain admins
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select Name,SamAccountName,Enabled, objectclass | sort-object -Property nameFind Disabled Domain admins & Sort
Get-ADGroupMember -Identity “Domain Admins” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | Select Name,SamAccountName,Enabled, objectclass | sort-object -Property name | Export-CSV C:\temp\DisabledDomainAdmins.csvFind Disabled Domain admins & Sort & Export to CSV
Get-ADGroupMember -Identity “GROUPNAME” -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $true}} | Select Name,EnabledFind members in a group
Get-Eventlog application -Newest 2000 | Where-Object {$_.entryType -Match “Error”}Find Latest errors in Eventlog
Get-Eventlog system -Newest 2000 | Where-Object {$_.entryType -Match “Error”}Find Latest errors in Eventlog
cd hkcu:Navigate Registry like filesystem
ps | sort –p ws | select –last 5Find the five processes using the most memory
Restart-Service DHCPRestar DHCP service
Get-ChildItem – ForceList all items within a folder
Get-ChildItem –Force c:\directory –RecurseList all items within a folder & all subfolders
Get-WmiObject -Class Win32_Service -Filter “state = ‘running’ and startmode = ‘auto'” | Select-Object name, startmode, description | Format-table -AutoSizeGet list of Services that start automatically
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’)Load SQL modules into memory 
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | out-null
$s = New-Object (‘Microsoft.SqlServer.Management.Smo.Server’) “servername”
$dbs | SELECT Name, Collation, CompatibilityLevel, AutoShrink, RecoveryModel
Discover SQL instances
Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name -eq”VmRemovedEvent”} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 19Find Vm’s Remove last 10 days
$wu = new-object -com “Microsoft.Update.Searcher”
 $totalupdates = $wu.GetTotalHistoryCount()
 $all = $wu.QueryHistory(0,$totalupdates)
 # Define a new array to gather output
 $OutputCollection=  @()        
Foreach ($update in $all)
    $string = $update.title
    $Regex = “KB\d*”
    $KB = $string | Select-String -Pattern $regex | Select-Object {$_.Matches }
     $output = New-Object -TypeName PSobject
     $output | add-member NoteProperty “HotFixID” -value $KB.‘ $_.Matches ‘.Value
     $output | add-member NoteProperty “Title” -value $string
     $OutputCollection += $output
 # Output the collection sorted and formatted:
$OutputCollection | Sort-Object HotFixID | Format-Table -AutoSize
Write-Host “$($OutputCollection.Count) Updates Found”
Command to get all Installed KB (Windows Update) from Server
frminst.exe /remove=agentForce uninstall McAffee when managed by another server (managed mode)

Linux Cheatsheet

Cheatsheets, Cheat Sheets 101

These cheats sheets are to be used on Linux Servers (Typically RHEL)


Cheatsheets, Cheat Sheets 101
CommandWhat is does?
route add -net netmask gw
Add a static root - substitute for your IP information
route del -net netmask gw
Remove static route
ifconfig eth1 netmask gw
Configure Ethernet
Location for Networking boot configuration
ifup eth1 boot

enable NIC at boot
ifdown eth1 boot
disabled NIC at boot
ip -s link
enable overview of traffic
dhclient eth01
dhclient ens33
get new IP from DHCP
basic Network config
cat /etc/resolv.confDNS server details
cat /etc/hostsLocal host file
cat /etc/services
Ports used for Firewall
iptable -F
Flush IPtables
iptables -I INPUT -p tcp --dport 48000 -j ACCEPTOpen port 48000 on firewall

Aix Cheatsheet

I’m a big fan of the verstility of of AIX. Its such a reliable OS and once you get your head around the concepts its very easy to manage and maintain. If you know Linux you can apply the majority of that knowledge to AIX.

Most of these commands will also work on Linux

CommandWhat it does
find / -xdev | xargs ls -ld | sort -rnk 5 | moreSearch AIX Filesystem for files
egrep –p “ Search string “ –f filename.loguseful for grep very large dsmsched.logs
q vol devclass=lto_tapeQueries Tape Library and Lists Scratch tapes
q reqlists requests to reply to
lscfg –vl fcs3Get details of a fibre card fcs3
nohup /opt/Tivoli/tsm/client/ba/bin/rc.tsmclient >/dev/null 2>&1Starts TSM Process
dd if=/dev/cdrom of=line500v7.1WindowsServer.iso bs=1024Command how to copy ISO on AIX
ls |sort |awk ‘{name=toupper($1);if(name==pre1) printf(“** %s  %s\n”,$1,pre2); pre1=name;pre2=$1}’AIX command used to find the duplicate files
find /var -xdev | xargs ls -ld | sort -rnk 5 | moreFinding large files in AIX (EG /VAR)
startsrc -s qdaemonrestart error daemon

Terraform Cheatsheet

CommandWhat it does?
terraform -install-autocompleteEnables tab completion
-helpShows the help files
applyapply the changes
consolecreates and interactive console
destroydestroys the Terraform-managed infrastructure
fmtused to rewrite Terraform configuration files
force-unlockused to remove lock on the state for the current configuration
getused to download and update modules
graphused to generate a a graph
importused to import existing resources
initused to initilize a working directory
outputused to extract the value of an output variable
planused to create an execution plan
providersused to print information about providers (eg VMware, AWS, HyperV etc etc etc)
pushused to upload your configuration
refreshused to update the state of a file
showuseds to provide output from a state or plan file
stateused for advanced state management
taintused to mark resources as tainted
validateused to validate the syntax of terraform files
untaintused to unmark a resourse as tainted
workspaceused to manage workspaces
Type or VariableWhat it does
"var" prefixUser String Variable
"var.MAP["KEY"]User Map Variable
Value of Key
"${var.LIST}"Value of the list as a list
List elements by Index
"self.ATTRIBUTE"Own Resource
"terraform.FIELD"Terraform Meta

San Volume Controller (SVC) Cheat Sheet

Command ▾Common Arguments & DescriptionCommand Description
svcinfo lsclusterDisplays cluster members id, name, location, ip-address etcDisplay info about clusters
svcinfo lscontrollerDisplays controllers id, name etcDisplay info about controllers visible to the system
svcinfo lsfabricDisplays remote_wwpn, remote_nportid, id, node_name, local_wwpn, local_port etcDisplay connectivity between nodes and other controllers and hosts
svcinfo lshostDisplays controllers id, name etcDisplay info about controllers visible to the system
svcinfo lshostvdiskmaphost1 (Obtain a list of the virtual disks that are mapped (visible) to host1, including vdisk_id, vdisk_name, wwpn etc)Obtain a list of the virtual disks that are mapped (visible) to a given host
svcinfo lsmdiskDisplays id, name, status, mode, mdisk_grp_name etc for all MDisksDisplay info about MDisks visible to the cluster
svcinfo lsmdiskgrpDisplays id, name, status, mdisk_count, vdisk_count, capacity etc for all MDisk groupsDisplay info about MDisk groups visible to the cluster
svcinfo lsrcconsistgrpapp_CG1 (Displays a detailed view of consistency group app_CG1 including state, status and sync attributesDisplays a detailed view of Metro or Global Mirror consistency groups visible to the cluster
svcinfo lsrcrelationshipDisplays id, name, master_cluster_name, master_vdisk_name, consistency_group_name etcDisplay information about all the Metro Mirror relationships visible to the cluster
svcinfo lsvdiskDisplays id, name, io_group_name, status, mdisk_grp_id, mdisk_grp_name, capacity etc for all VDisksDisplay information about VDisks recognized by the cluster
svcinfo lsvdiskvdisk1 (Displays detailed information about vdisk1 including mdisk_grp_name and remote copy relationship RC_name)Display detailed information about a specific VDisk recognized by the cluster
svctask mkrcrelationship-master master_vdisk_name -aux aux_vdisk_name -cluster cluster_name -name data_1 (Creates a new rc relationship named data_1)Creates a new Metro or Global Mirror relationship with virtual disks (VDisks)
svctask mkvdisk-mdiskgrp 0 -iogrp 0 -size 50 -vtype striped -unit gb -name app1_1 (Create a vdisk named app1_1)Create a sequential, striped of image mode Vdisk
svctask mkvdiskhostmap-host host1 -scsi 1 app1_1 (Create a new mapping between vdisk app1_1 and host1 assigning SCSI LUN ID 1 to app1_1 on host1)Create a new mapping between a virtual disk and a host making the vdisk accessible for I/O to the specified host
svctask startrcconsistgrp-primary master -force (Start the consistency group copy process, specifying the copy direction (the master becomes the primary) even if the copy process leads to a temporary loss of consistency during synchronisation (-force))Start the Metro or Global Mirror consistency group copy process
svctask startrcrelationshiprc_rel_app1 (Start the remote copy relationship for relationship name rc_rel_app1)Starts the Metro Mirror or Global Mirror relationship copy process
svctask stoprcconsistgrp-access app_CG1 (Stops the copy process for consistency group app_CG1 and allows write access to consistent secondary VDisks in app_CG1 (-access))Stops the copy process for a Metro Mirror or Global Mirror consistency group