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...
Try this variation
Get-VM | where {$_.Name -match [regex]"[\$\(\)\s]+"} | Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
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.
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.
Try this variation
Get-VM | where {$_.Name -match [regex]"[\$\(\)\s]+"} | Select Name
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nice! This time it worked fine.
Could you explain the functioning of this arguments?
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
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
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