-
-
Save MVKozlov/e656f0df0ae829106fb91f4186dd41fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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