vSphere High Performance Cookbook

vSpere High Performance Cookbook

I’ve been working on a little side project recently — reviewing a book for Packt Publishing.  This process has given me a new respect for authors and the process behind writing a book.  The book – vSphere High Performance Cookbook – has been published and you can check it out here: http://bit.ly/14sDuyk.

Here is an overview of the book:

  • Troubleshoot real-world vSphere performance issues and identify their root causes
  • Design and configure CPU, memory, networking, and storage for better and more reliable performance
  • Comprehensive coverage of performance issues and solutions including vCenter Server design and virtual machine and application tuning
Posted in Virtualization | Leave a comment

Script to ping a list of computer names

A few weeks ago, I co-worker asked for a script to ping a list of computer names. I thought I had one on my blog, but couldn’t find it. I decided to post a copy here to make it easier to find in the future. This is very simple, and doesn’t do any sort of multithreading, but for a short list it will get the job done pretty quick:

[cc lang=”powershell”]
$ping = New-Object system.net.networkinformation.ping
Get-Content someComputerList.txt | %{
try {$results = $ping.Send($_).Status } catch { $results = $false }
New-Object psobject -Property @{ Name=$_ ; Results=$results }
}
[/cc]

Posted in Scripting | Leave a comment

Reviewing DNS logs with PowerShell

I recently helped out on a project where DNS services were being moved to different hosts with new IP addresses. After updating the DHCP scope options and static DNS configuration settings on all servers, the team turned on DNS logging to look for any hosts still using the old DNS servers. The logs contained a lot more records than originally anticipated, so I wrote the following code to help summarize the logs.

This first block of code found all of the DNS queries that didnt come from domain controllers, manipulated the log file entry to get just the source IP and stored all the results in a collection named myResults.

[cc lang=”powershell”]
# Create a pipe separated list of domain controllers
$listOfDCs = “192.168.0.40|192.168.5.20|192.168.10.60”
$loopbackIPv6 = [regex]::Escape(“::1”)

$myResults = @()
Get-Content e:\dnslogs\dns.log | ?{$_ -match ‘ PACKET ‘ -and $_ -match “UDP Rcv ” -and $_ -notmatch $listOfDCs -and $_ -notmatch $loopbackIPv6} | %{
$sourceIP = (($_ -split(“UDP Rcv “))[1] -split(” “))[0]
$myResults += New-Object psobject -Property @{
SourceIP = $sourceIP
FullLine = $_
} # end new object
} # end dns log loop
[/cc]

Once we rearranged the data so that it would be more usable, we wanted to find the source IP addresses responsible for the majority of the lookups. The idea here is that once you resolve the issue with these hosts, you can recreate the DNS log file and the next pass through will contain fewer entries and therefor run faster. Using powershell this is a pretty quick one liner after you run the block of code above.

[cc lang=”powershell”]
$myResults | Group-Object -Property SourceIP | Sort-Object Count -Descending
[/cc]

That is helpful, but the team really wanted to know host name. Using the data from host naming convention, they could tell what team would be responsible for resolution of the issue. With just a few more lines of code we can easily return that information too.
[cc lang=”powershell”]
# Since server guys are more likely to know host names than IP address, we will loop through the resutls and
# lookup the host name, then sort the list to find the largest number of lookups
$myResults | Group-Object -Property SourceIP | Sort-Object Count -Descending | %{
$sourceName = try { [system.net.dns]::GetHostByAddress($_.Name).HostName } catch { “UNKNOWN” }
New-Object psobject -property @{
HostName = $sourceName
IP = $_.Name
Count = $_.Count
}
}
[/cc]

Posted in Scripting | Leave a comment

Powering on a virtual machine from the command line

I recently made a post about powering on virtual machines in bulk using PowerCLI. That process worked well to power on VMs in vCenter, but what if you need to turn on vCenter? In some cases (lockdown mode, firewall rules, etc) you may need to power on a VM from the tech support console of an ESXi host. vSphere has accountted for this through the use of vim-cmd commands in the local console. The first command will return the ID for each VM on a host. The second command accepts one of these IDs to execute a power on operation:

vim-cmd vmsvc/getallvms
vim-cmd vmsvc/power.on ##

VMware has a good KB article on the subject: 1038043 | Powering on a virtual machine from the command line when the host cannot be managed using vSphere Client.

Posted in Virtualization | Leave a comment

Quickly power on virtual machines with PowerCLI Get-View

I recently had a need to power on a lot of virtual machines in a specific order. I was given several text files each numbered with a startup sequence. At a specific time I would be given a number and need to power on all of the virtual machines associated with that startup sequence number. Several minutes later I would be given another number and need to power on all of those virtual machines. Using Get-VM and Start-VM really wasn’t an option… even with -RunAsync that option was kind of slow.

The option I finally settled on involved using Get-View to return a list of all virtual machines; I would then use Where-Object to find the specific VM and finally invoke the PowerOnVM_Task to start the VM. During some testing, I realized this was almost too fast. Nearly all of the power on tasks would queue up in vCenter and all the VMs would power on in very large batches. To keep things somewhat controlled, I added a very short .5 second delay between virtual machine power on tasks.

[cc lang=”Powershell”]
$serverList = Read-Host “Which list would you like to power on? ”
$view = Get-View -ViewType ‘virtualmachine’ -Property Name

$taskTracker = @()
Get-Content “$serverListList.txt” | %{
$vmName = $_
Write-Host “Now powering on VM: $vmName … ” -nonewline
$taskTracker += ($view | ?{$_.name -eq “$vmName” }).PowerOnVM_Task($null)
Start-Sleep -Milliseconds 500
Write-Host “done!”
}
“Submitted $($taskTracker.Count) power on requests”
[/cc]

2013/10/20 Update: Just to clarify, I had files named 1list.txt, 2list.txt, 3list.txt and so on, each containing a virtual machine name listed one per line of the file. When the Read-Host cmdlet asked ‘Which list would you like to power on?’ I just answered 1, 2 or 3. The script automatically appends the list.txt to the file name on the Get-Content line.

This script can potentially throw some errors that are not accounted for in code, but weren’t a show stopper in my situation. First of all, this script does not account for vApps or scenarios where multiple virtual machines have identical names. vApps typically have their own startup order defined within the app. This process will turn on member VMs but may or may not be in the correct order. Another problem would be if you have two virtual machines with the same name, such as “UI VM”. This script will not turn on either (however it could be modified slightly to do so). The last issue I’m aware of is that this process will attempt to turn on any virtual machine in the list without first checking to see if the virtual machine is currently running. If a VM was powered on before my script reached it, the error “The operation is not allowed in the current state” was logged in vCenter and in the script. In my situation this was acceptable.

Posted in Scripting, Virtualization | 2 Comments