Automation

 View Only
  • 1.  script to check a setting in a vmx file

    Posted Apr 13, 2012 02:39 PM

    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



  • 2.  RE: script to check a setting in a vmx file
    Best Answer

    Posted Apr 13, 2012 03:40 PM

    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}} }


  • 3.  RE: script to check a setting in a vmx file

    Posted Apr 13, 2012 05:04 PM

    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...



  • 4.  RE: script to check a setting in a vmx file

    Posted Apr 13, 2012 06:28 PM

    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.



  • 5.  RE: script to check a setting in a vmx file

    Posted Apr 13, 2012 03:58 PM

    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"} }
    }