PowerCLI: Enable Changed Block Tracking


image
If you don’t know what Changed Block Tracking is, just read this excellent post from Eric Siebert.

You can check the status of Changed Block Tracking with the following PowerCLI one-liner:

Get-VM | Get-View | `
Sort Name | Select Name, `
@{N="ChangeTrackingStatus";E={$_.Config.ChangeTrackingEnabled}}

The output of the one-liner will look like this:

image

If you’re running a VM with only one VMDK, you can use the following function to enable Changed Block Tracking:

Function EnableChangeTracking{
    param($vm)
    $vmView = Get-VM $vm | Get-View

    if($vmView.Config.Version -eq "vmx-04"){
        Write-Host -ForegroundColor Red `
        "The Virtual Hardware version of this VM does not support Changed Block Tracking"
        return
        }

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.changeTrackingEnabled = $true
    $vmView.ReconfigVM($vmConfigSpec)

    sleep 3

    Get-VM $vm | New-Snapshot -Name "Temp" 

    sleep 5

    Get-VM $vm | Get-Snapshot | Where {$_.Name -eq "Temp"} | Remove-Snapshot -Confirm:$false
}

You can run the function via the following command:

image

I am going to updated the function later, so it will be able to enable Changed Block Tracking on a VM with multiple VMDKs.

Update: When the VM is powered off, you are able to set the Changed Block Tracking feature for all the VMDKs.

Update 2: There was a little chat about this subject on Twitter between @lamw @gabvirtualworld and me (@afokkema) where @gabvirtualworld posted the following tweet:

image

I can confirm this theory and update my script with this little trick. Now you’re able to enable Changed Block Tracking when your VM is powered on.

PowerCLI: Change Persistence mode (on the fly)


image

When you have some vmdk’s with the Independent Persistent mode enabled. You might get problems with Storage vMotion (some DMotion errors). I was able to fix this with disabling  the Independent mode and create and remove a snapshot of the VM. But within the vSphere client you’re not able to change the Independent setting of a running VM. With PowerCLI you can!

The first one-liner will return all the vmdk’s with the Independet Persistent mode enabled:

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} }

This is what you see in the console.

image

Within the vSphere client, you can’t change this setting while the VM is powered on.

image

But why use the vSphere client when we have PowerCLI ;-). If you run the following one-liner, it will return all the vmdk’s with Independent Persistent mode enabled. The next step is to disable this setting.

Get-VM | % { Get-HardDisk -VM $_ | Where {$_.Persistence -eq "IndependentPersistent"} | `
% {Set-HardDisk -HardDisk $_ -Persistence "Persistent" -Confirm:$false} }

This is the output you’ll see:

image

When you check the settings within the vSphere client, you’ll notice that the Independent mode is disabled.

image

PowerCLI: Two Virtual Switch and Portgroup one-liners


image

In this post you’ll find two Powershell one-liners to do some maintenance on Virtual Switches and PortGroups.

The first one-liner is inspired by Hany Michel his post: vMotion vs. VMotion .. Vote for your favorite! In this post he starts the debate about which name it should be. I voted for the “new” name vMotion. If you want to change the name of the VMotion portgroups to the “new” standard. You can do this by hand but why, we got PowerCLI 😉 The following one-liner will do the job:

Get-VMhost | % { Get-VirtualPortGroup -VMhost $_ -Name VMotion `
| Set-VirtualPortGroup -Name vMotion -Confirm:$false }

The vSwitches with the VMotion Protgroup name will be changed to vMotion:image

 

The next one-liner will change the number of ports on vSwitch0. The default setting on vSwitch0 is 24 ports.

image

With PowerCLI you can easily change this again with an one-liner. This one-liner will change the value to 120 ports:

Get-VMHost | % {Get-VirtualSwitch -VMHost $_ -Name vSwitch0 | `
where {$_.NumPorts -lt "128"}} | `
% { Set-VirtualSwitch -VirtualSwitch $_ -NumPorts "128" }

You’ll see the following output:

image

You need to reboot the ESX host to apply the new setting.

VMware: vSphere & PowerCLI Update 1 released


image image

Finally the vSphere Client is supported on Windows 7 & Windows Server 2008 R2:

Windows 7 and Windows 2008 R2 support — This release adds support for 32-bit and 64-bit versions of Windows 7 as well as 64-bit Windows 2008 R2 as guest operating system platforms. In addition, the vSphere Client is now supported and can be installed on a Windows 7 platform.

 

You can find the downloads and release notes here:

 

ESX 4.0 Update 1: http://downloads.vmware.com/d/details/esx40u1/ZHcqYmQlcGpiZGVqdA==

Release note: http://downloads.vmware.com/support/vsphere4/doc/vsp_esx40_u1_rel_notes.html

 

ESXi 4.0 Update 1: http://downloads.vmware.com/d/details/esxi40u1/ZHcqYmQlcGhiZGVqdA==

Release Notes: http://downloads.vmware.com/support/vsphere4/doc/vsp_esxi40_u1_rel_notes.html

 

vCenter 4.0 Update 1: http://downloads.vmware.com/d/details/vc40u1/ZHcqYmQlcCpiZGVqdA==

Release notes: http://downloads.vmware.com/support/vsphere4/doc/vsp_vc40_u1_rel_notes.html

 

vSphere PowerCLI 4.0 Update 1: http://downloads.vmware.com/d/details/sdkwin40u1/ZHcqYmQlcHRiZGVqdA

Release notes: http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/windowstoolkit40U1-200911-releasenotes.html

vSphere: Storage vMotion Fails with a Timeout


image

When I tried to Storage vMotion a VM to another LUN I got an “operation timed out error”:

image

After analyzing the vpxd.log, I found the following lines:

image

The best part I found out, is that the VM was rolled back to it’s old location without losing data or getting corrupt.

This problem is documented in KB1010045. The following solution will resolve the timeout problem:

Increase the Storage VMotion fsr.maxSwitchoverSeconds setting in the virtual machine configuration file to a larger value.

The default is 100 seconds.

To modify fsr.maxSwitchoverSeconds:

  1. Right-click the virtual machine and click Edit Settings.
  2. Click the Options > Advanced > General.
  3. Click Configuration Parameters.
  4. From the Configuration Parameters window, click Add Row.
  5. For the Name field,  fsr.maxSwitchoverSeconds and for the Value field enter the new timeout value.
  6. Click OK twice to save.
  7. Restart the virtual machine for the changes to take effect.

You don’t want to change this by hand, so I created a PowerCLI script which will set the fsr.maxSwitchoverSeconds to 300 seconds for all your VM’s:

$vms = Get-View -ViewType VirtualMachine | where {-not $_.config.template}

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
      
    $extra = New-Object VMware.Vim.optionvalue
    $extra.Key="fsr.maxSwitchoverSeconds"
    $extra.Value="300"

    $vmConfigSpec.extraconfig += $extra
    

foreach($vm in $vms){
    $vm.ReconfigVM($vmConfigSpec)
}

After changing the value to 300 seconds, I was able to Storage vMotion the VM.

PowerCLI: One-Liner to get VMs, Clusters, ESX Hosts and Datastores


image

With the one-liner below, you’re able to create an overview of your VM’s, Clusters, ESX Hosts and Datastores.

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} 

The following output will be generated:

image

If you add an extra line with the export-csv cmdlet, you can export the output to a CSV file.

Get-VM | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="ESX Host";E={Get-VMHost -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}} | `
Export-Csv -NoTypeInformation C:\Scripts\VM_CLuster_Host_Datastore.csv 

If you want, you can import the CSV file into Excel. Excel has some basic filtering options, so you’re able to filter on ESX Host, Cluster etc.

image

Project Onyx released – How to connect and use it


image image

Carter Shanklin just announced the release of Project Onyx. She his post here: http://blogs.vmware.com/vipowershell/2009/11/project-onyx-is-here.html

Download the zip file from here: http://bit.ly/vmwOnyx15 extract the zip file and start Onyx.exe. If you’re starting Onyx from your c: drive and you are running Windows Vista / , you’ve to run it with Administrator rights:

image

Accept the License Agreement to continue. The main screen opens. Click on connect and fill in the IP Address of you vCenter server:

image

When you’re connected to your vCenter server, Remember the second IP Address on top of the Onyx Screen:

image

Now open the vSphere Client and connect to the second IP Address with http:// on front of it:

image

You will see a warning message about the connection to server xxx.xxx.xxx.xxx is not secure. Click yes to continue.

The vSphere client opens and it will look and feel like we’re used to it. But here comes the great part. Click on the play button in Onyx:

image

Do the thing you wanted to do within the vCenter client and you will see that Onyx is generating some nice ready to use PowerCLI code:

image

To save the script, press the Save output to file button.

image

VMware Tools: Default disk timeout settings


image 

On a new Windows Server 2003 server without the VMware Tools installed, there are no TimeOut settings configured.

You can find this setting in the following registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Disk\

The picture below, you’ll see the default settings from Microsoft:

image

After the installation of the VMware Tools, a new dword value called TimeoutValue is added with the hexadecimal value of 3c. This value represents a timeout of 60 seconds.

image

On a Linux VM the default timeout is 60 seconds (on a CentOS setup). You can find the timeout settings in:

/sys/block/<disk>/device/timeout

image

After the installation of the VMware Tools, the timeout value is changed to 180 seconds.

image

 

More info about this subject can be found here:

vCenter 4.0 and SQL 2008 as a Database server


image

Last week I had to install a vCenter 4.0 server with a database on a SQL 2008 x64 server. Before you can connect to the SQL 2008 x64 you have to install the new SQL server 2008 Native client. You can find it here:

Download and install the package:

image

In my earlier post about how to create an ODBC connection to use with vCenter 4 on a x64 version of Windows 2008. You already read about the “special” way of starting the ODBC data Source Administrator. Start it via: Start –Run – %systemdrive%\Windows\SysWoW64\Odbcad32.exe. The next step is to select the new Native Client version 10.0

image 
The rest of the stuff is still the same 😉