Skip to content

Instantly share code, notes, and snippets.

@MVKozlov
Last active May 5, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MVKozlov/e656f0df0ae829106fb91f4186dd41fa to your computer and use it in GitHub Desktop.
Save MVKozlov/e656f0df0ae829106fb91f4186dd41fa to your computer and use it in GitHub Desktop.
PS C:\> $a = 'ExtensionData.Config.Files.VMPathName'
PS C:\> Get-VM some-server
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
some-server PoweredOn 1 4,000
PS C:\> $vm = Get-VM some-server
PS C:\> $vm.ExtensionData.Config.Files.VMPathName
[Some-SAN] some-server/some-server.vmx
PS C:\> $vm.$a
PS C:\> # Look - it empty because PS can't resolve full property path
PS C:\> # Solution principle demonstration:
PS C:\> $b,$c,$d,$e=$a -split '\.'
PS C:\> $b,$c,$d,$e
ExtensionData
Config
Files
VMPathName
PS C:\> $vm.$b.$c.$d.$e
[Some-SAN] some-server/some-server.vmx
PS C:\> # Not empty - I build property path one by one !
PS C:\> # The trick itself. On each cycle step $obj go deeper and deeper by property path
PS C:\> $a -split '\.' | Foreach-Object -Begin { $obj = $vm } -Process {$obj = $obj.$_ } -End { $obj }
[Some-SAN] some-server/some-server.vmx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment