Tuesday, March 22, 2011

Install VMware Tools without a reboot.


Get-VM | Where {$_.PowerState -eq "PoweredOn" -and $_.Guest.OSFullName -match "Win*"} | % {Update-Tools -VM $_ -NoReboot}
#(Found this on ICT-freak.nl)

Thursday, March 10, 2011

Start Remote Tech Support using PowerCli

Get-VMHost myESX.com  | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService




 

Tuesday, March 1, 2011

Recreate missing vmdk files

Today a colleague of mine (or me) did a mistake browsing the datastores using the vSphere-Client.
He found a folder with a machine (srv01) that he believed was discontinued, he market the "srv01" folder and pressed delete...
After a while the vSphere-Client showed an error message saying that some files were in use.
What happened was that the vmdk files were deleted (description-files) but the srv01-flat.vmdk (the actual datadisks) files were not deleted due to the fact that the VM was running.
The server was still running but for some reason my colleague decided to reboot the server... Bad idea.
The server complain about missing files and would not start.

Below solved the issue for me.
To recreate the description files i did as follow.
Enable RemoteTechSupport on the ESX that host the VM.
Login to the ESX using putty.
Browse to the datastore where the srv01-flat.vmdk reside.
To get the size of the vmdk do an "ls-l srv01.vmdk "
Note the size of the vmdk.
Use vmkfstools : " vmkfstools -c 4874254770 -d thin -a lsilogic new.vmdk"
Remove the "flat-new.vmdk"
Rename the new.vmdk to the same name as the missing vmdk. (srv01.vmdk)
Use Veeam to browse the datastore and rightclick and edit the srv01.vmdk file.
Change the name on the line RW 132432543  "new-flat.vmdk" to  srv01-flat.vmdk
Now you should be able to boot your VM again.

Source VMware KB 1002511

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" }