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

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

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

Will Invoke-VMScript work ?

The Invoke-VMScript cmdlet can be a very useful cmdlet, but sometimes it will fail against one or more of your VMs. And it is not always immediately clear why the Invoke-VMScript cmdlet will not work against that specific VM.
The cmdlet help contains a number of prerequisites, but how do you verify if all the prerequisites are fulfilled?
I decided to create a function that would verify the prerequisites, and that would, if requested, which of the prerequisites was missing.

Continue reading Will Invoke-VMScript work ?

Storage Views – Datastores

In the vCenter Client, since vSphere 4, you can find a Storage Views tab on several of the VI containers. The data in these Storage Views is collected and provided by the vCenter Storage Monitoring plug-in.

Have a look at David Davis‘s post, called Using VMware vSphere Storage Views, for more information on what you can do with the Storage Views.

Some time ago I got a question from Andrew how the Multipathing Status presented in the Storage Views could be detected and reported upon by a PowerCLI script. What looked rather simple at first, turned out to be a bit more difficult than I anticipated.

Continue reading Storage Views – Datastores

PowerCLI at VMworld US

Last year’s sessions by Alan and myself definitely was one of the highlights of my year. And judging by the comments and scores we received, it didn’t go down that badly with the attendees either. So this year we want to “raise the bar”. We have some fantastic sessions planned and hope you will come and see some of the things we have organised.

If I had to use one word to describe our sessions this year it would be “Super”. After you have seen the sessions you will understand why.

So to give you an idea of what we have planned we decided to give you a quick outline of our sessions and also a mention some of the other PowerShell and PowerCLI based sessions at VMworld….

And don’t forget to register in time !

Continue reading PowerCLI at VMworld US

VIProperties in a Module

Judging from the number of hits, the VIProperties page seems to be rather popular.
The number of entries on that page increases nearly on a daily basis.And judging by the list of people who submitted New-VIProperty entries, this particular feature of PowerCLI is in use all over the place.
Recently my co-author of the PowerCLI book, Jonathan Medd, had a brilliant idea.

Why not bundle all the VIProperties in a module ? The user would just have to do an Import-Module, instead of a copy/paste on each of the entries.

So for the 100th post on my blog I decided to bring you the VIProperty module.

Update August 25th 2011: added the use of the PowerCLI 5 Get-VIProperty cmdlet.

Continue reading VIProperties in a Module

VMX Raiders Revisited

This afternoon news of a new (and interesting) blog post from Julian Wood hit the Twitter-verse.

He took part from the logic of my Raiders of the Lost VMX script and used the relatively new VMFilePath parameter of the New-VM cmdlet, to shorten my script considerable. Well done, great job !

But I was intrigued by a remark in Julian’s post. He was obviously not too fond of using MoRefs in a script. But in Julian’s final script I still saw a Get-View cmdlet and the use of the HostDatastoreBrowser. Remembering a remark from one of my co-authors on the PowerCLI book, that the Get-View cmdlet would disappear, once the PowerCLI snapin would be sufficiently evolved, I decided to tackle Julian’s script and give it another simplification treatment and make it more PowerCLI 😀

Continue reading VMX Raiders Revisited