PowerCLI: Windows Disk Alignment on VMware

Searching for disk alignments off the windows 2003 servers on VMware ESX i found a CLI script which can automate the search. The original site: http://ict-freak.nl/2009/12/15/powercli-check-partition-alignment-windows-vms-only/

Script:

$myCol = @()
$vms = get-vm | where {$_.PowerState -eq "PoweredOn" -and `
$_.Guest.OSFullName -match "Microsoft Windows*" } | Sort Name 

foreach($vm in $vms){
$wmi = get-wmiobject -class "Win32_DiskPartition" `
-namespace "root\CIMV2" -ComputerName $vm            

    foreach ($objItem in $wmi){
        $Details = "" | Select-Object VMName, Partition, Status
            if ($objItem.StartingOffset -eq "65536"){
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition aligned"
            }
            else{
                $Details.VMName = $objItem.SystemName
                   $Details.Partition = $objItem.Name
                $Details.Status = "Partition NOT aligned"
            }
    $myCol += $Details
    }
}
$myCol | Export-Csv -NoTypeInformation "C:\PartitionAlignment.csv"
#$myCol | Export-Clixml "C:\PartitionAlignment.xml"

PowerCLI: VMware Backup Script

Searching for way’s to create easy backup’s of a few virtual machines, i came on the website gestalt it (http://gestaltit.com/all/tech/virtualization/simon/vmware-backup-powercli-script/).

On this website there is a script which will create a snapshot of a VM, then clone it (thin provisioned) and finally remove the snapshot off the original VM.

Backup Script

# Import Backup CSV
$backupinfo =  Import-Csv C:\scripts\mybackups.csv

#Set Date format for clone names
$date = Get-Date -Format "yyyyMMdd"

#Set Date format for emails
$time = (Get-Date -f "HH:MM")

#Connect to vCenter
Connect-VIServer ""

foreach ($customer in $backupinfo)
{
	$vm = Get-VM $customer.MasterVM

	#Send Start Email
	C:\scripts\backupstartedemail.ps1

	# Create new snapshot for clone
	$cloneSnap = $vm | New-Snapshot -Name "Clone Snapshot"

	# Get managed object view
	$vmView = $vm | Get-View

	# Get folder managed object reference
	$cloneFolder = $vmView.parent

	# Build clone specification
	$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
	$cloneSpec.Snapshot = $vmView.Snapshot.CurrentSnapshot

	# Make linked disk specification
	$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
	$cloneSpec.Location.Datastore = (Get-Datastore -Name $customer.BackupDS | Get-View).MoRef
	$cloneSpec.Location.Transform =  [Vmware.Vim.VirtualMachineRelocateTransformation]::sparse

	$cloneName = "$vm-$date"

	# Create clone
	$vmView.CloneVM( $cloneFolder, $cloneName, $cloneSpec )

	# Write newly created VM to stdout as confirmation
	Get-VM $cloneName

	# Remove Snapshot created for clone
	Get-Snapshot -VM (Get-VM -Name $customer.MasterVM) -Name $cloneSnap | Remove-Snapshot -confirm:$False

	#Send Complete Email
	C:\scripts\backupcompletedemail.ps1
}
#Disconnect from vCentre
Disconnect-VIServer -Confirm:$false

Send Started Email Script

#Set Date format for emails
$timestart = (Get-Date -f "HH:MM")

$emailFrom = ""
$emailTo = ""
$subject = "[$vm - Backup Started]"
$body = "Backup Details
-------------
VM Name:",$vm,"
Clone Name:","$vm-$date","
Target Datastore:", $customer.BackupDS,"
Time Started:", $timestart

$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom,$emailTo,$subject,$body)

Send Completed Email Script

#Set Date format for emails
$timecomplete = (Get-Date -f "HH:MM")

$emailFrom = ""
$emailTo = ""
$subject = "[$vm - Backup Complete]"
$body = "Backup Details
-------------
VM Name:",$vm,"
Clone Name:","$vm-$date","
Target Datastore:", $customer.BackupDS,"
Time Started:", $timestart,"
Time Completed:", $timecomplete
$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom,$emailTo,$subject,$body)

CSV File

The content of the csv file is very simple. This is what mine looks like:

MasterVM,BackupDS
VM1,BackupDataStore
VM2,BackupDataStore

ESX Host’s disconnected

ESX communicates with virtual center through what is loosely described as, “management agents”. When you hear TSE’s talk about “management agents”, we’re really talking about 3 things: vpxa, hostd, and vpxd 

 Vpxa lives on the ESX host (on the service console), it communicates with hostd. It’s mostly a listener service, and is very rarely an issue. Hostd lives on the ESX host (on the service console). This is the lion, the vast majority of “disconnects” indicate a problem with hostd, and vpxd lives on your virtual center server. These 3 services form a communications chain, and failure of one or more of these services, tends to produce “disconnects”.

Restarting the Management agents on an ESX or ESXi Server

To restart the management agents on ESX host:
  1. Log in to your ESX Server as root from either an SSH session or directly from the console of the server.
  2. Type “service mgmt-vmware restart”.
    Caution: Ensure Automatic Startup/Shutdown of virtual machines is disabled before running this command or you risk rebooting the virtual machines.
  3. Press Enter.
  4. Type “service vmware-vpxa restart”.
  5. Press Enter.
  6. Type “logout” and press Enter to disconnect from the ESX host.
To restart the management agents on ESXi:
  1. Connect to the console of your ESXi Server.
  2. Press F2 to customize the system.
  3. Login as “root”.
  4. Using the Up/Down arrows navigate to Restart Management Agents.
  5. Press Enter.
  6. Press F11 to restart the services.
  7. When the service has been restarted, press Enter.
  8. Press Esc to logout of the system.

Links:

Automating VMware with PowerShell

LAB Summary
Welcome to the Automating VMware with PowerShell: Hands-On Lab. This lab will provide you hands-on experience in writing PowerShell scripts for managing VMware using the VI Toolkit (for Windows). Each participant will create scripts that will show you how to more effectively manage your virtual infrastructure. Some familiarity with PowerShell is helpful, but is not required. 
 
LAB Objective
The objective of this lab is to introduce you to the VI Toolkit (for Windows) and show you how easy automating VMware Virtual Infrastructure management is when you use PowerShell. We will cover a wide range of topics, including things like provisioning, storage, networking and monitoring. 

 Link: http://blogs.vmware.com/vipowershell/files/vmworld_europe_2008_powershell_lab_7_manual.pdf

Or local download: [wpdm_file id=”15″]

TS Licensing Step-by-Step Guide

How should I prepare to use TS Licensing?
To use TS Licensing to manage TS CALs, you will need to do the following on a server running Windows Server 2008:

  1. Install the TS Licensing role service.
  2. Open TS Licensing Manager and connect to the Terminal Services license server.
  3. Activate the license server.
  4. Install required TS CALs on the license server.

For a detailed instruction, browse to: http://technet.microsoft.com/en-gb/library/cc754034(WS.10).aspx

Keep in mind that a terminal server running Windows Server 2008 cannot communicate with a license server running Windows Server 2003. However, it is possible for a terminal server running Windows Server 2003 to communicate with a license server running Windows Server 2008.

Windows Disk timeout is not set at default

source: http://technet.microsoft.com/en-us/library/aa997069(EXCHG.80).aspx

Disk timeout is not set at default

This topic is intended to address a specific issue called out by the Exchange Server Analyzer Tool. You should apply it only to systems that have had the Exchange Server Analyzer Tool run against them and are experiencing that specific issue. The Exchange Server Analyzer Tool, available as a free download, remotely collects configuration data from each server in the topology and automatically analyzes the data. The resulting report details important configuration issues, potential problems, and nondefault product settings. By following these recommendations, you can achieve better performance, scalability, reliability, and uptime. For more information about the tool or to download the latest versions, see “Microsoft Exchange Analyzers” at http://go.microsoft.com/fwlink/?linkid=34707.

The Microsoft® Exchange Server Analyzer Tool reads the following registry entry to determine whether the disk time-out value has been changed from the default value:

HKEY_LOCAL_MACHINESystemCurrentControlSetServicesDiskTimeOutValue

If the Exchange Server Analyzer finds the TimeOutValue present and configured with any value other than 10, and the server is non-clustered, a non-default configuration message is displayed. If the Exchange Server Analyzer finds the TimeOutValue present and configured with any value other than 20, and the server is clustered, a non-default configuration message is displayed.

Disk time-out is a registry setting that defines the time that Microsoft Windows® will wait for a hard disk to respond to a command. On a non-clustered system, this key is not present and a default value of 10 seconds is used for all disks. On a Windows cluster, this key is present and uses a default value of 20 seconds. If the time-out time is more than the value in this registry setting, Windows will show an error and will stop disk access. Sometimes, this may be set to a greater value if you are running multipath disk-access software. Multipath software lets you connect multiple physical paths (such as fiber) to a single disk drive for redundancy. Multipath software manages the multiple physical connections so that Windows handles only a single handle to the disk.

Installing host bus adapters (HBA) or other storage controllers can cause this key to be created and configured. When you install or reinstall these drivers, the TimeOutValue registry value is overwritten with the value that is required by those drivers. You may have to contact the hardware vendor to determine the correct TimeOutValue registry value for your configuration.

To revert to the default configuration

  1. Open a registry editor, such as Regedit.exe or Regedt32.exe.
  2. Navigate to:

    HKLMSystemCurrentControlSetServicesDiskTimeOutValue

  3. In the right pane, delete the TimeOutValue entry. Alternatively, double-click the TimeOutValue entry and set it to one of the following values:
    • On a non-clustered server, set the value to 10.
    • On a clustered server, set the value to 20.
    • If your hardware manufacturer recommends a different value for either a clustered or non-clustered system, use the value from your hardware manufacturer instead.
  4. Close the registry editor, and then restart the computer for the change to take effect.