Automation

 View Only
  • 1.  Find Lower Case VMs

    Posted Sep 10, 2015 04:34 AM

    Hi all,

    Trying to find all the lowercase VMs so I can then rename to UPPERCASE.

    When I run my command below it only returns a single lowercase VM when I know I have a lot more than one.

    Can someone push me in the right direction please?

    Thanks....

    get-vm | Where-Object { $_.name -match "[A-Za-z]+_[A-Za-z]+" }



  • 2.  RE: Find Lower Case VMs

    Posted Sep 10, 2015 08:45 AM

    You must use cmatch command:

    $vms = (Get-VM -Name TEST_vm).Name

    if ($vms -cmatch '^[A-Z\0-9\s-]*$') {write-host "name has allowed chars"} else {Write-Warning "name has low chars"}


    In this case allowed chars are A-Z, 0-9 and -


    First line puts in $vms variable only VM name. You should probably change $vms variable to an array.

    If all your VMs must be uppercase, you can also use ToUpper() method. Try this:

    $vms.ToUpper()



  • 3.  RE: Find Lower Case VMs

    Posted Sep 10, 2015 09:37 AM

    Try like this

    Get-VM | where {$_.Name -cmatch "^[a-z]+_[a-z]+$"}



  • 4.  RE: Find Lower Case VMs

    Posted Sep 10, 2015 09:32 PM

    The only one I found to work was this...

    get-vm | Where-Object { $_.name -cmatch "[a-z]+" }



  • 5.  RE: Find Lower Case VMs

    Posted Sep 11, 2015 01:03 AM

    What is the layout of your VM names then ?

    Is it "abc-xyz" like your first code seems to suggest, or "abc" like this last code seems to suggest ?



  • 6.  RE: Find Lower Case VMs

    Posted Sep 11, 2015 11:35 AM

    This should work.  I've used it in reverse to rename all upper to lower case.  I left the -Whatif there, but I usually change it to -confirm:$false

    get-vm | where { $_.name.ToLower() -ceq $_.name } | foreach { Set-VM -VM $_ -Name ($_.name.ToUpper() ) -whatif }