PowerCli Get-VM

VM Cpu and Memory
get-VM | select Name, CpuUsageMhz, MemoryUsageGB

 

VM with CPU Limit
Get-VM | Get-VMResourceConfiguration | where {$_.CPULimitMhz -ne ‘-1’}

 

Setting the CPU limit to unlimited
Get-VM | Get-VMResourceConfiguration | where {$_.CPULimitMhz -ne ‘-1’} | Set-VMResourceConfiguration -CPULimitMhz $null

 

VM with Memory Reservation
Get-VM | Get-VMResourceConfiguration | where {$_.MemReservationMB -ne ‘0’}

 

Setting the memory reservation to 0
Get-VM | Get-VMResourceConfiguration | where {$_.MemReservationMB -ne ‘0’} | Set-VMResourceConfiguration -MemReservationMB 0

 

Locate VMs with snapshots
get-VM | get-snapshot | select VM, Name, SizeGB, Created

 

Export vm list with snapshot
Get-VM | Get-Snapshot | format-list | out-file c:\snapshots.txt

 

Locate VMs with snapshots you can do a bit of inline math to round it correctly using inbuilt functions
get-VM | Get-Snapshot | select VM, Name, @{ n=”SpaceUsedGB”; e={[math]::round( $_.SizeGB, 2)}}, created

 

Export vm information
Get-VM | Select-Object Name,NumCPU,MemoryMB,PowerState,Host | Export-CSV VMs.csv -NoTypeInformation

 

Export the data to a file
get-VM | select * | export-csv ‘C:\Users\Stuart\Desktop\vmlist.csv’ -NoTypeInformation

 

Get all running vm’s
Get-VM -ComputerName Server1 | Where-Object {$_.State -eq ‘Running’}

 

Export and sort by the server power state
get-VM | select * | sort Powerstate | Export-Csv ‘C:\Users\Stuart\Desktop\test4.csv’ -NoTypeInformation.

 

List all those VMs with attached CD-ROMs. When a CD-ROM is attached, the VM can’t migrate between hosts.
get-VM | where { $_ | get-cddrive | where { $_.ConnectionState.Connected -eq “true” } } | select Name

 

Get VMWare Tools Version
get-vm |% { get-view $_.id } | select Name, @{Name=”;ToolsVersion”;; Expression={$_.config.tools.toolsVersion}}

 

Get vm attributes 

get-vmhost esx1.lab.local | get-vm | Get-Annotation -CustomAttribute “attribute” | Where-Object { $_.Value -eq “UAT” }

 

 

 

 

Please Comment and Subscribe

Leave a Reply

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