about 1 week ago - 3 comments
Recently released on the PowerCLI site there has been an updated version of the PowerCLI Poster, this time the PowerCLI Documentation and Engineering teams have done a great job of updating it into a readable poster and have even added my quick reference guide to it to make it an awesome document. Included in this
about 1 week ago - 4 comments
A few times in PowerGUI or generally I have needed the user to select a single entity so that I can use this entity further in the code to narrow down the output, with this in mind i created a quick PrimalForms form which can be used as a function and a single object selected,
about 1 month ago - 2 comments
As we announced in our post “We’re writing a book!”, Luc and myself started writing a PowerCLI book. At about the same time I got a once-in-a-lifetime opportunity to join EMC as a vSpecialist, how could I turn that down ! Now you don’t become a vSpecialist for free, I have been spending a fair
about 1 month ago - 4 comments
Recently at the London VMware User Group I gave an additional presentation on top of the normal PowerCLI session I normally provide (which was interactive this time and I think worked very well). The subject of this session was “Why EMC for VMware”, I have had a number of questions from people who know that
about 1 month ago - 1 comment
I have been given my normal resident slot at the London VMUG this Thursday, 15th July. At the last VMUG I showed how vEcoShell could be used to add the graphical interface back onto our PowerCLI scripts and also gave an overview of the “VMware Community PowerPack”, when performing the demo I showed how easy
about 3 months ago - 1 comment
A little while back I started a PowerPack which could be used in either PowerGUI or vEcoShell – the application formerly known as “The Virtualisation EcoShell or VESI, my PowerPack was a collection of the most used scripts from my site all laid out in a nice GUI format. Now why would you put a
about 4 months ago - 9 comments
Some of you might be interested to know, Alan and Luc are writing a PowerCLI book. We don’t have many more details at the moment but wanted to let you know, as we are both very excited (and nervous by the amount of work) about this project. As you know we both live and breathe PowerCLI. And we
about 4 months ago - 2 comments
I was recently contacted via my blog and asked if there was a way to find the VMs which are not named in vCenter the same as they are in Active Directory or their hostname, the person contacting me had explained that someone had “accidently” renamed a number of VMs and when there was an
about 4 months ago - No comments
You may have noticed a distinct lack of posts from me recently, I have been on holiday, I had a great time staying in Belgium and The Netherlands, a fantastic country which I would recommend to anyone thinking about travelling in northern Europe, not just for the red lights or “space cakes” either ! Whilst
about 1 year ago
A very “usable” article.
And for completeness sake, the regex version:
…
$VmPathName = $VM.Summary.Config.VmPathName
$Folder = ([regex]“\[\w+\] (\w+)/”).match($VmPathName).Groups[1].Value
$Path = ([regex]“(\[\w+\] \w+)/”).match($VmPathName).Groups[1].Value
…
Regex is your friend
about 1 year ago
@LucD
As always AMAZING ! Thanks Luc
about 1 year ago
This is a pet peeve of mine for a while now, I am very anal about VMs like this I always end up changing the names of the directory name or even filename’s by either svmotioning or using vmkfstools to match GUI (presumably what I wanted!)
Thanks the for the article.
about 1 year ago
@amusica
Consistency is the key, thanks for the comment.
about 1 year ago
You think of everything that’s annoyed me in the last couple of years. Perfect and thanks again. Glad I found this site.
about 1 year ago
@Alex
Thanks for the kind comments
about 11 months ago
Thank you for the awesome script!
@LucD
Thank you for the regex LudD. However, I am having some problems with the matching when there is a non-word character (e.g. dash or underscore) in the VM Name. Any suggestions?
about 1 month ago
Hello-
@Harley
You should probably be able to change the regex from using word characters to using any, since the matching/grouping in this instance is based on the “] ” and the trailing “/”. That is, like so:
…
$VmPathName = $VM.Summary.Config.VmPathName
$Folder = ([regex]“\[.+\] (.+)/”).match($VmPathName).Groups[1].Value
$Path = ([regex]“(\[.+\] .+)/”).match($VmPathName).Groups[1].Value
…
For efficiency’s sake, you could also write it as:
…
if ($VmPathName -match “(\[.+\] (.+))/”) {$Folder = $Matches[2]; $Path = $Matches[1];}
…
(50% fewer calls to “match”). And, for clarity’s sake, you could add some named capture groups (such as “?”):
…
if ($VmPathName -match “(?\[.+\] (?.+))/”) {$Folder = $Matches['folder']; $Path = $Matches['path'];}
…
Matt
about 4 weeks ago
Doh, looks like the code was broken a bit due to interpreted/discarded angle brackets . That last part should have been something like:
…(50% fewer calls to “match”). And, for clarity’s sake, you could add some named capture groups (such as “?<path>“):
if ($VmPathName -match “(?<path>\[.+\] (?<folder>.+))/”) {$Folder = $Matches['folder']; $Path = $Matches['path'];}
…that is, if I have it right, now (no preview for this comment).