Category: Powercli

Powercli: Get VM’s With CPU and Memory Reservation

Powercli: Get VM’s With CPU and Memory Reservation

Get-VM | Where-Object {$_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation -ne "0" -or $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation -ne "0"}
PowerCLI: Memory Usage Report Script

PowerCLI: Memory Usage Report Script

The Below one liner will generate a CSV file containing the following

  • VM Host
  • VM Folder
  • VM Name
  • VM Memory Allocation
  • VM Memory Average Usage Last 30 Days
PowerCLI C:\> get-vm | Where {$_.PowerState -eq "PoweredOn"} | sort Name | Select-Object VMHost,Folder,Name,MemoryGB,@{N="Memory Usage (Average Over 30 Days), %" ; E={[Math]::Ro
und((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} | Format-Table -autosize -Property VMho
st,Folder,Name,MemoryGB,"Memory Usage (Average Over 30 Days), %" | Export-Csv C:\temp\MemoryUsage.CSV
PowerCLI: Set VM Tools Time Sync

PowerCLI: Set VM Tools Time Sync

Please see below for the snippet to enable VM time sync with host time via VMware Tools using PowerCLI

$vm = Get-VM -Name "TEST-VM-01"
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.changeVersion = $vm.ExtensionData.Config.ChangeVersion
$ = New-Object VMware.Vim.ToolsConfigInfo
$ = $true
$_this = Get-View -Id $vm.Id
PowerCLI: Rename VM Inventory Name

PowerCLI: Rename VM Inventory Name

If you have seen my older post about changing the Windows hostname I have also had the challenge of changing the VM names within the inventory to match. Here is the rather simple solution to do this

set-vm Old-VM-NAME=01 -name 'New-VM-Name=01' -confirm:$false
set-vm Old-VM-NAME=02 -name 'New-VM-Name=02' -confirm:$false
set-vm Old-VM-NAME=03 -name 'New-VM-Name=03' -confirm:$false