Monday, February 28, 2011

PowerCli-VMwareResourceConfig

At a customer i find that resource config on VMs where strange i.e Cpu shares and Memshares where set to custom values which nobody could defend.
I used this script to set it back to default.

#Change resource config to normal and no mem and cpu limits
Get-VMHost "yourVMHostName" | Get-VM | Get-VMResourceConfiguration | `
 Set-VMResourceConfiguration -CpuSharesLevel "Normal" -MemSharesLevel "Normal" -CpuLimitMhz $null -MemLimitMB $null

PowerCli-upgrade VMwareTools at next powercycle

# Change VM config to upgrade vmwaretools at next powercycle.
# Change upgradeatpowercycle to manual to revert changes
$vms = get-vmhost "yourESXhost" | get-vm
ForEach($vm in $vms) {
$vm_view = $vm | get-view
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
$vm_view.ReconfigVM_Task($vmConfigSpec)
}

PowerCli-PathPolicy

Need to change the pathpolicy to RoundRobin on all your datastores and dont have the time to "right-click" every datastore?
Use this PowerCli script.


#Change pathpolicy to RR for all LUNs on VMHost
Write-Host Change pathpolicy to RoundRobin on all host in cluster.
$esxhost = Get-Cluster clustername | get-vmhost
foreach ($esxhosts in $esxhost)
{Get-ScsiLun -VmHost (Get-VMHost $esxhosts) -LunType disk |  Set-ScsiLun -MultipathPolicy "roundrobin" }