russ79
Enthusiast
Enthusiast

script to check a setting in a vmx file

Jump to solution

I'm fairly new to the powershell thing and I'm looking for a help with creating a simple script that will parse through vmx files looking for the disk.enableUUID setting. We've had to set many to false to allow backups, and with a new backup software version, I'm looking to find these VMs so i can change it back to true... the settings were added using the advanced paramaters in the general settings of the vm

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

foreach($vm in Get-VM){
  $vm.ExtensionData.Config.ExtraConfig |
  where {$_.Key -eq "disk.enableUUID"} |
  select @{N="VM";E={$vm.Name}},@{N="disk.enableUUID";E={$_.Value}} }


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try something like this

foreach($vm in Get-VM){
  $vm.ExtensionData.Config.ExtraConfig |
  where {$_.Key -eq "disk.enableUUID"} |
  select @{N="VM";E={$vm.Name}},@{N="disk.enableUUID";E={$_.Value}} }


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

View solution in original post

0 Kudos
VTsukanov
Virtuoso
Virtuoso

or

take a look at Retrieve and Set VM Advanced Configuration (VMX) settings add function

function Get-VMAdvancedConfiguration { 
<#
.SYNOPSIS
  Lists advanced configuration setting (VMX Setting) for a VM
  or multiple VMs
.DESCRIPTION
  The function will list a VMX setting for a VM
  or multiple VMs
.PARAMETER VM
  A virtual machine or multiple virtual machines
.EXAMPLE 1
  PS> Get-VM MyVM1 | Get-VMAdvancedConfiguration
#>

  param(
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
      $vm,
      [String]$key
  )

  process{ 
    if ($key) {
        $VM | Foreach {
            $_.ExtensionData.Config.ExtraConfig | Select * -ExcludeProperty DynamicType, DynamicProperty | Where { $_.Key -eq $key }
        }
    } Else {
        $VM | Foreach {
                $_.ExtensionData.Config.ExtraConfig | Select * -ExcludeProperty DynamicType, DynamicProperty
            }
    }
  } 
}

and run

Get-VM | ForEach-Object {
     echo $_ | where { Get-VM $_ | Get-VMAdvancedConfiguration -key disk.enableUUID | where {$_.Value -eq "true"} }
}
russ79
Enthusiast
Enthusiast

this worked perfectly, thanks... one question though... where does the ExtensionData.Config.ExtraConfig come from? I dont see it listed as a property of get-vm... just trying to wrap my head around how this little loop works...

0 Kudos
LucD
Leadership
Leadership

Through the ExtensionData property you get access to the underlying SDK object, in this case the VirtualMachine object.

This gives you access to all the properties and methods that are present on the SDK objects.


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

0 Kudos