VMworld 2012 Sessions – Public Voting

It’s that time of the year again I’m afraid.

While this blog tried to bring you useful PowerCLI scripts and functions throughout the year, I now have to revert into begging mode. The VMworld Call for Papers Voting is open !

If you enjoyed one or more of the blog posts here, or if I answered one of your questions in the PowerCLI Community, or if you enjoyed one of our sessions during a previous VMworld, please cast your vote on the sessions I submitted for VMworld 2012.

Session 1328 is offering the best of all worlds. It will answer all the questions you might have about Automation and vSphere. The panel includes superstars William Lam and Alan Renouf, and the master of ceremonies is none other than Pablo Roesch. You can’t go wrong with this session !

Session 1329, which I submitted together with my long-time co-presenter and co-author Alan Renouf, will be the sequel to our successful Best Practices session from last year. There will be a ton of new best practices ! When you use PowerCLI, or intend to use it, this is the session you shouldn’t miss.

Thanks for your vote 🙂

Continue reading VMworld 2012 Sessions – Public Voting

Folder by Path

There seem to be many vSphere environments where the same foldername is used multiple times. A blue folder with the name Servers is quite common for example.

If you need to retrieve such a folder with the Get-Folder cmdlet, you will have to walk the path to the folder leaf by leaf and use the Location parameter. It would be handier if you could just specify the path to the folder and retrieve the folder like that.

The following is a small function that will allow you to do just that.

Update August 6th 2020: The missing NoRecursion switch caused folders by the same name, further down in the hierarchy, to be returned as well.

Update July 5th 2019: The functions have been updated to support the situation where a user is connected to multiple vSphere Servers.

Update February 18th 2016: In some situations the function might return folders with the same name from different location. Fixed by adding NoRecursion on line 48
Continue reading Folder by Path

vNIC transmit and receive rates

The VMTN PowerCLI Community is a constant source of inspiration for blog posts. User roswellevent raised, in the thread Any way to get virtual machine Nic card usage?, the question if it was possible to get the transmit and receive rate for each vNIC in virtual machines.

Since I’m interested in all things statistics in vSphere I decided to tackle the question. Finding the metrics to use for this kind of report is not too difficult. Under the PerformanceManager Network section we find the metrics net.received.average and net.transmitted.average. And, provided your Statistics Level is set to 3 for the timeframe you want to report on, the metrics capture statistics on the device level.

Great, exactly what we need! A quick check in the Performance tab in the vSphere Client showed an additional problem to solve. The instance didn’t mention Network Adapter 1 but a number.

Continue reading vNIC transmit and receive rates

Test if the datastore can be unmounted

Lately I have been playing around with the new Storage related features in vSphere 5. One of the novelties is that you can now unmount a VMFS datastore and detach a SCSI LUN through the API.
To be able to unmount a datastore, some conditions have to be met. In the vSphere Client you get an informative popup that tells what is prohibiting the datastore unmount. If not all conditions are met, you can not continue with the unmount.

Nice feature, but what for those of us that want to automate this ?

Update October 28th 2012: Take into account that the datastorecluster is not connected to a host that is part of a cluster. Skip the HA heartbeat test.

Update April 23th 2012: Use the RetrieveDasAdvancedRuntimeInfo method to find the actual datastores that are used for the heartbeat.

Continue reading Test if the datastore can be unmounted

Automate your VMTN search

Recently I had the pleasure of doing a guest post, called Finding your way in the PowerCLI Community, on the PowerCLI blog. The subject of the post was how to find community threads, that might hold an answer to your question.

Now this wouldn’t be a PowerShell/PowerCLI blog, if I didn’t try to automate the procedure. And with a serious amount of RegEx involved, I was able to create some working code. Here it is, my Find-VMTNPowerCLI function.

Warning: pure PowerShell, no PowerCLI content !

Continue reading Automate your VMTN search

dvSwitch scripting – Part 12 – Find free ports

On the PowerCLI Community there was an interesting question about dvSwitches, portgroups and connecting VMs. Turns out you will need to provide a free port to connect a VM’s NIC to a portgroup on dvSwitch.
Since the solution is a nice follow up on my previous, somewhat lengthy post, called Variations on a port, I decided to create a short post on the subject in my dvSwitch series.

Update 3th March 2016: added test to capture portgroups with no VM connected to it

Continue reading dvSwitch scripting – Part 12 – Find free ports

Variations on a port

I got an interesting question from one of my co-authors of the PowerCLI Reference book. He was looking for a method to find the port used by a VM when connected to a portgroup on a dvSwitch.

Finding the answer to that question is not too difficult, once you know which property holds the value. But while writing and testing the script, I thought that this question would be a good opportunity to show several ways and methods that you have at your disposal in PowerCLI and PowerShell, to come to a solution.

Here it goes.

Continue reading Variations on a port

Get complete vCenter session info

There was an interesting thread in the PowerCLI Community today. It raised the question how one could report on the current vCenter sessions, including the IP address or hostname from where the session was started.

Unfortunately the SessionManager doesn’t hold any information from where the session was started.

But there are other ways of finding that information. The UserLoginSessionEvent object has a property, called ipAddress, that has the information we’re after.

Btw if you are only interested in looking for idle sessions, independent from which host they were started, there is a great post, called List and Disconnect vCenter Sessions on the PowerCLI blog.

Update May 4th 2012: function updated to handle multiple vCenter connections.
Continue reading Get complete vCenter session info

Proxy cmdlet revisited: Connect-VIServer and Disconnect-VIServer

In PowerCLI 5.0.1 a handy feature that showed the connected vSphere Servers in the title bar of the PowerCLI window was apparently removed.
In a PowerCLI Community thread some users found this a useful feature that they would like to have back.
I’m sure the PowerCLI Team will listen to their users and fix this problem in the coming PowerCLI version.

But while we are waiting for a new PowerCLI build that brings back the title bar text, you can fix this for yourself thanks to the proxy cmdlet feature.

Continue reading Proxy cmdlet revisited: Connect-VIServer and Disconnect-VIServer

Change the root password in hosts and Host Profiles

For good security measures you should change the password of your root account on your ESX(i) servers on a regular basis. Instead of logging on to each and everyone of your ESX(I) servers, you can easily automate this process.

But what about the new ESX(i) hosts you will roll out in between root password changes and where you use a Host Profile to configure these new ESX(i) hosts ? Will you need to run a script after the deployment to change the root password ?

Turns out that you can easily update  the root password in your Host Profile with the help of an SDK method.

Continue reading Change the root password in hosts and Host Profiles