Getting ESX VM paths with PowerCLI

By YellowOnline on Monday 13 July 2015 12:07
Category: Powershell, Views: 3.737

I see quite some people trying to figure out how to get the folder of a virtual machine with PowerCLI (basically, an ESX PoSh module) and most solutions I see involve complex constructions with Get-Folder. That's really not necessary: as you would expect, the VM Object contains this information. It's just a bit hidden


If we get the members of Get-VM, there's the Folder property to make you think the information would be hidden somewhere there. Well, it isn't. Or at least I didn't find it. While researching I did stumble into a property called ExtensionData, but to no avail. At least: until I saw the same property on its parent.



code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
PS H:\> (Get-VM $VM).ExtensionData


Capability           : VMware.Vim.VirtualMachineCapability
Config               : VMware.Vim.VirtualMachineConfigInfo
Layout               : VMware.Vim.VirtualMachineFileLayout
LayoutEx             : VMware.Vim.VirtualMachineFileLayoutEx
Storage              : VMware.Vim.VirtualMachineStorageInfo
EnvironmentBrowser   : EnvironmentBrowser-52-envmgr
ResourcePool         : ResourcePool-ha-root-pool
ParentVApp           :
ResourceConfig       : VMware.Vim.ResourceConfigSpec
Runtime              : VMware.Vim.VirtualMachineRuntimeInfo
Guest                : VMware.Vim.GuestInfo
Summary              : VMware.Vim.VirtualMachineSummary
Datastore            : {Datastore-172.0.0.1:/volesxbackupXXX}
Network              : {Network-HaNetwork-VM Network 1}
Snapshot             :
RootSnapshot         : {}
GuestHeartbeatStatus : gray
LinkedView           :
Parent               : Folder-ha-folder-vm
CustomValue          : {}
OverallStatus        : green
ConfigStatus         : green
ConfigIssue          : {}
EffectiveRole        : {-1}
Permission           : {}
Name                 : YELLOWSRV01_Backup_201507131112
DisabledMethod       : {setCustomValue, AddTag, RemoveTag, RefreshStorageInfo...}
RecentTask           : {}
DeclaredAlarmState   : {}
TriggeredAlarmState  : {}
AlarmActionsEnabled  : False
Tag                  : {}
Value                : {}
AvailableField       : {}
MoRef                : VirtualMachine-52
Client               : VMware.Vim.VimClient



Those first properties looked promising, so I expanded further. Finally:


code:
1
2
3
4
5
6
7
8
9
PS H:\> (Get-VM $VM).ExtensionData.Config.Files


VmPathName        : [TWEAKERSSRV101:esxbackupXXX] YELLOWSRV01_Backup_201507131112/YELLOWSRV01_Backup_201507131112.vmx
SnapshotDirectory : [TWEAKERSSRV101:esxbackupXXX] YELLOWSRV01_Backup_201507131112
SuspendDirectory  : [TWEAKERSSRV101:esxbackupXXX] YELLOWSRV01_Backup_201507131112
LogDirectory      : [TWEAKERSSRV101:esxbackupXXX] YELLOWSRV01_Backup_201507131112
DynamicType       :
DynamicProperty   :

Volgende: Windows 10: MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED 08-'15 Windows 10: MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED
Volgende: Tien live-opnames om te zien (en te horen) op YouTube 06-'15 Tien live-opnames om te zien (en te horen) op YouTube

Comments

Comments are closed