VMware Cloud Community
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

Restrict VM's display name

Someone know if it's possible to resctrict the change of display name of a VM?


I don't want to leave a VM with special Characters into your name, for example VM(1). the parentesis bother me on scripts and searches...

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try this variation

Get-VM | where {$_.Name -match [regex]"[\$\(\)\s]+"} | Select Name 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
8 Replies
CRad14
Hot Shot
Hot Shot
Jump to solution

Hmm, Well I am not sure the PowerCLI forums is the best place for this...unless of course you wanted a script to find vms with displaynames that have special characters.

I am not sure what you are asking can be done, short of changing the permissions so individuals simply cannot change VM display names

Conrad www.vnoob.com | @vNoob | If I or anyone else is helpful to you make sure you mark their posts as such! 🙂
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Restricting the characters used in a VM name is afaik not possible.

This will display the VMs that have, what regex considers non-word characters, in their names.

The regex word characters are 'A-Za-z0-9_' (not including the quotes)

Get-VM | where {$_.Name -match [regex]"\W+"} | Select Name 

Does this list the VMs you are after ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

I'm afraid not Luc, I ran the script you mentioned and returns all my VMs

I want to return only the VMs that have any special character in the name, like "$" or "("

We use a foreign backup tool here and it fails if some VM has special character in the name. Smiley Sad

EDITED:

     I forgot to talk... we can't have spaces between tha name too. Like "My VM" or "VMware HealthAnalyzer"... the spaces were the last problema related by the backup team.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try this variation

Get-VM | where {$_.Name -match [regex]"[\$\(\)\s]+"} | Select Name 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

Nice! This time it worked fine.

Could you explain the functioning of this  arguments?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It uses a regular expression (regex) and in the mask I specify the characters ($ and both parenthesis and any white-space) you want to look for.

Since these are meta-characters for regex, they need to be escaped by the back-slash


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
GuilhermeStela
Enthusiast
Enthusiast
Jump to solution

I read about regex and seems very complicated at the begginning but finally undestood.

Now i have to map all special characters and put in the expression.

Tks again Luc. =D

0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you work with RegEx expressions it's handy to use a tool to validate your  pattern.

Something like this for example.

I personally use RegExBuddy regularly.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos