Friday, February 17, 2012

How to find where a VM is hosted

A fairly common problem is if you know a machine is virtual but you don't know where it is hosted. A perfect example is if you get notified that a machine in your environment has a virus and needs powered off but nobody knows where the machine is hosted. This gets even more interesting when you have nested virtual ESX hosts with guests running under them. With a quick google search I found 2 PowerCLI scripts that got close to what I wanted and then tweaked them to make this process very easy.

1. Script #1 is a modified version of the script located on VMware's website on information about the CDP network information: and allows you to find what host is tied to a specific CDP enabled switchport. Change the port in bold and cut and paste into PowerCLI

------ Start Script -----
Get-VMHost Where-Object {$_.State -eq "Connected"}
%{Get-View $_.ID}
%{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem}
%{ foreach($physnic in $_.NetworkInfo.Pnic){
$pnicInfo = $_.QueryNetworkHint($physnic.Device)
foreach($hint in $pnicInfo)

if( $hint.ConnectedSwitchPort.PortID -eq "GigabitEthernet3/13" )
Write-Host We have a match... $esxname is connected to remote switch port $hint.ConnectedSwitchPort.PortID on $physnic.Device -fore green
Write-Host "Not guilty..."; Write-Host
----- End Script ----

Script #2 is a very slightly modified script that I got from one of the comments at and modified ever so slightly to show current power state.

------ Start Script -----
Get-VM where { (Get-NetworkAdapter $_).MacAddress -eq "00:50:56:86:01:f1" } Format-Table Name,Host, PowerState
----- End Script ----

Nothing terribly original but hopefully it will help somebody else.

Monday, February 13, 2012

Disk Space Woes

So I have a 160GB hard drive in a laptop and I am using 155 GB of it but I can only account for about 60 GB... how do I find what is eating all my space...?

Try this really cool little program, Space Sniffer.

Thursday, February 2, 2012

Configuring Openfiler iSCSI and VMware Data Recover (vDR)

If you have some extra hardware floating around with reasonable disk space you can use it as a cheap iSCSI device to store non-critical VM backups using VDR. The process is pretty easy and works really well. I have several of these running in our lab, including some that are Openfiler running as a VM on ESX 5 and even then performance is pretty good. This article assumes that you already have Openfiler ( installed on a piece of hardware and the networking configured. For sure I recommend running 2 nics, one for management and the second as a private iSCSI network. Once all that is done all you need to do is configure the storage and iSCSI on the Openfiler box as well as your ESX host. Let's see how we acomplish that:

1. Login to the Openfiler web interface and click on the Volumes tab and then on the right sidebar select Block Devices.

2. Select the section that says "Create a partition in /dev/sd(b)" The settings you use are: "Mode = Primary", "Partition Type = Physical Volume". Starting and Ending cylinders are set automatically to the largest setting and do not need modified unless you so choose. Then hit "Create"

3. Now click on the "Volume Groups" option on the right sidebar and you will see an option to "Create a new volume group". Check the box for the physical volume you just created and give it a name like "VDR".

4. Once that is complete click on the "Add Volume" option on the right sidebar and select your new "VDR" volume group. Under the section "Create a volume in 'VDR'" you can create a new volume. Name it something like "VDR" and give it all the available space. MAKE SURE that you change the "Filesystem / Volume Type" to iSCSI.

5. Your storage is ready, now we need to get iSCSI running. To do this you need to start the iSCSI Target Service and allow network access. To start the service click on the "Services" tab on the top toolbar and start the service. To get the iSCSI Network up and running go back to the "Volumes" tab and "iSCSI Targets". Now you will notice 4 grey tabs under your top toolbar. Using these tabs create a new IQN under the "Target Configuration" tab and give your private iSCSI LAN access via the "Network ACL" tab.

6. Now that iSCSI is running we need to map the IQN to the LUN that we created earlier. It is as easy as going to "LUN Mapping" and selecting the LUN and hitting "Map". Your job in the Openfiler webconsole is complete. Now off to the ESX host.

7. Open your vSphere Client and connect to your vCenter Server and your ESX host that is connected to the Openfiler box. I am assuming that you have already configured a NIC on the ESX host and it can ping the Openfiler private IP. If not you need to get that working before continuing.

8. In the vSphere client select the ESX host and go to the "Configuration" tab and select "Storage Adapters" from the left sidebar. Now select the "iSCSI Software Adapter" and click "Properties...". Click on the "Configure..." button and enable iSCSI. Once iSCSI is enabled click on the "Dynamic Discovery" tab and add the IP of your Openfiler box. Once that is done and you Ok out of the menu it will prompt you to do a rescan which you want to do. If it all went well then once the Rescan is complete you should see a new device. If not then make sure your 2 boxes are talking to each other.

9. Now that our iSCSI Adapter can talk to our shiny Openfiler box we need to actually use that space to store our VDR backups. To do this click on the "Storage" option and select "Add Storage" option. This should bring up a wizard explaining how to add the storage. Name the new Datastore something like "VDR Backups".

10. Right click on your VDR Appliance and go to "Edit Settings" and "Add.." a new hard drive making sure to select the new Datastore you just created. Don't give the drive all the space on the Datastore. Make sure to leave several GB free for ESX to use for file operations.

11. Congratulations, now all you need to do is add the Datastore to your VDR Appliance as a backup destination!