PowerCli One-liners for VMware.
This post covers some powercli "One Liners" which will help the VMware admin's to make the day smooth and simplify their day-to-day tasks on VMware.
Here we go...
Query the vmware tools
on all virtual machines
get-vm |% { get-view $_.id } | select Name, @{ Name=”Tools
Status”; Expression={$_.guest.toolsstatus}}, @{ Name=”Tools Running Status”;
E=$_.guest.toolsrunningstatus}}
Query the nic type of
all virtual machines
Get-VM | Get-NetworkAdapter | Select-Object Parent,Type
Query the disk type of
all virtual machines
get-vm | foreach-object -process {get-harddisk $_} |
select-object storageformat | format-list
Get VMs with Memory
Reservations
Get-VM | Get-VMResourceConfiguration | Where
{$_.MemReservationMB -ne 0} | Select VM,MemReservationMBGet-VM |
Get-VMResourceConfiguration | Where {$_.MemReservationMB -ne 0} | Select
VM,MemReservationMB
Get VMs with CPU Reservations:
Get-VM | Get-VMResourceConfiguration | Where {$_.CpuReservationMhz -ne 0} | Select VM,CpuReservationMhz
Get-VM | Get-VMResourceConfiguration | Where {$_.CpuReservationMhz -ne 0} | Select VM,CpuReservationMhz
Get VMs with Memory Reservations
Get-VM | Get-VMResourceConfiguration | Where {$_.MemReservationMB -ne 0} | Select VM,MemReservationMB
Get-VM | Get-VMResourceConfiguration | Where {$_.MemReservationMB -ne 0} | Select VM,MemReservationMB
Get VMs with CPU Reservations:
Get-VM | Get-VMResourceConfiguration | Where {$_.CpuReservationMhz -ne 0} | Select VM,CpuReservationMhz
Get-VM | Get-VMResourceConfiguration | Where {$_.CpuReservationMhz -ne 0} | Select VM,CpuReservationMhz
Retrieve VM snapshots
older than three months
Get-VM | Get-Snapshot | Where {$_.Created -lt
(Get-Date).AddDays(-90)} | Select-Object VM, Name, Created, SizeMB
Remove-Snapshot older snapshot
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-120)} | Remove-Snapshot -Confirm:$false
Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-120)} | Remove-Snapshot -Confirm:$false
VM-snapshot count
Get-VM | Where {(Get-SnapShot -VM $_ | Measure-Object).Count -gt 2} | Format-Table Name | Export-CSV C:\snapshot_counts.csv
Get-VM | Where {(Get-SnapShot -VM $_ | Measure-Object).Count -gt 2} | Format-Table Name | Export-CSV C:\snapshot_counts.csv
Get-VM | Format-Table Name,
@{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ |
Measure-Object).Count}}
Find RDMs in your
environment
Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | SelectParent,Name,ScsiCanonicalName,DiskType
Mass storage Vmotion
Get-VM -Datastore <SourceDatastore1>
| Move-VM -Datastore<TargetDatastore> -runasync
Take multiple vm's snapshots using single command
Here all the VM's need to be dragged into single folder before running
this on liner.
get-vm -location
“floder_name” | New-Snapshot -Memory -Quiesce -Name <snapshot_name>
-Description "Created $(Get-Date)"
Disabling CDrom for
Vmotions
(Get-VM
-Location:(Get-Datacenter "NMC Tools")) | Get-CDDrive | Where {
$_.IsoPath } | Set-CDDrive -NoMedia -Confirm:$false
Find the VM's disk
location by datacenter's.
get-datacenter
"datacenter_name" | Get-VM | Select Name,
@{N="Cluster";E={Get-Cluster -VM $_}}, `@{N="ESX
Host";E={Get-VMHost -VM $_}}, `@{N="Datastore";E={Get-Datastore
-VM $_}}
Check VMWare Tools Version
get-vm |% { get-view
$_.id } | select Name, @{ Name=";ToolsVersion";;
Expression={$_.config.tools.toolsVersion}}
Multipath status per
Host within ClusterGet-Cluster "Acceptance" |
Get-VMHost | where {$_.State -eq "Connected"} | Select Name,
@{N="TotalPaths";E={($_ | Get-ScsiLun | Get-ScsiLunPath |
Measure-Object).Count}}
Find all Dead Paths In
a Datacenter
ForEach ($vmhost in (Get-Datacenter "The Netherlands" | Get-Vmhost | Sort)){ $deadpaths = Get-ScsiLun -vmhost $vmhost | Get-ScsiLunPath | where {$_.State -eq "Dead"} | Select ScsiLun,State; Write-Host $vmhost $deadpaths}
ForEach ($vmhost in (Get-Datacenter "The Netherlands" | Get-Vmhost | Sort)){ $deadpaths = Get-ScsiLun -vmhost $vmhost | Get-ScsiLunPath | where {$_.State -eq "Dead"} | Select ScsiLun,State; Write-Host $vmhost $deadpaths}
Find All LUN IDs in
use on an ESX Server
Get-ScsiLun -vmhost esx01 -luntype disk | select runtimename | sort runtimename
Get-ScsiLun -vmhost esx01 -luntype disk | select runtimename | sort runtimename
Comments
Post a Comment