Insanely simple and incredibly useful code snipits

Stuff that saves time… if you can remember it..!

A growing collection of simple one-liners.

 

List vms with Name

Get-VM | Where {$_.Name -like “Web*”}

 

Get by Blue Folder

$f = Get-Folder <“folder name”>
$folder = (Get-Folder $f | Get-View)
$foldervms = Get-View -SearchRoot $folder.MoRef -ViewType “VirtualMachine” | Select Name

 

How many virtual wires?

> $totalvwires = Get-VirtualPortGroup |  ? {$_.Name -like “vxw-dvs*”}
> $totalvwires.count

How many ports?

$numports = Get-VirtualPortGroup |  Select NumPorts
> $numports.count

 

Import vms from text file

$vms = Get-Content C:\vSpherePowerCLI\Input\vmlist.txt | foreach { Get-VM $_ }

 

Tools version (requires powercli 5.2 R2)

> get-vm  <vm> | get-vmguest | select VMName, ToolsVersions | FT -autosize

 

Quick check of highest vm cpu ready stats

Get-Stat -entity $vm -IntervalSecs 300 -stat ‘cpu.ready.summation’ | sort-object value -descending | Select-Object -first 25 | format-table -auto

 

Quick check of highest stats

List possible stat types (availability on vcenter depends on configured Statistics Level)

> Get-StatType -Entity $esx -Start (get-date) | Sort-Object -Unique

> Get-Stat -entity $vm -IntervalSecs 300 -stat ‘<stat type>’ | sort-object value -descending | Select-Object -first 25 | format-table -auto

 

Check Guest OS disk assignment and usage

List OS view of disk assignment, disk name, capacity, and free space in GB and percentage

$VM = get-vm <vm name>

$vm.Extensiondata.Guest.Disk | Select @{N=”Name”;E={$vm.Name}},DiskPath, @{N=”Capacity(GB)”;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=”Free Space(GB)”;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=”Free Space %”;E={[math]::Round(((100* ($_.FreeSpace))/ ($_.Capacity)),0)}}

 

Get NFS disk assignment

C:\vSpherePowerCLI\Scripts> Get-Datastore | where {$_.type -eq “NFS”} | Select ParentFolder,Name,RemoteHost,RemotePath | ft

List all nfs datastores, ip and path

 

Get NFS Status for all hosts in cluster

$vmhosts = get-cluster SHDBCN-E | get-vmhost

foreach ($vmhost in $vmhosts) {Get-Datastore | ? {$_.Type -eq “NFS”} | Select ParentFolder, RemoteHost, RemotePath, Type, Accessible| ft -a}

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *