VMware Cloud Community
jsouthwell
Contributor
Contributor
Jump to solution

Unable to add 'workingDir' to VMX files

I need to verify that each VM has a 'workingDir' set in the VMX file and if it is not set to set it to a value. Checking for the value does not seem to be a problem.

Get-VM | get-tkevmx | where {$_.key -eq "workingDir"}

When I try to set the value it appears to go through the motions without errors, but the value is not set.

Get-VM myVM | set-tkevmx -key "workingdir" -value "/vmfs/volumes/newdir/myVM/"

The above works if I change the -key string to any other setting. What am I doing wrong?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Perhaps try a path with this syntax:

$vmConfigSpec.Files.snapshotDirectory = "[vmfsname] /SnapDir"

where "vmfsname" is the name you have given to the datastore,

and "Snapdir" is a directory in the root of that datastore.

Also note that there is a blank between the closing square bracket and the forward slash.


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

This problem is not caused by the Set-TtkeVmx method but with the underlying ReconfigVM method.

It is a similar problem as the one I mentioned in .

You can't use the extraOptions object to change the snapshot folder since there is an option in the VirtualMachineFileInfo object.

This is how you can change the "workingDir" entry.

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Files = New-Object VMware.Vim.VirtualMachineFileInfo
$vmConfigSpec.Files.snapshotDirectory = "/vmfs/volumes/newdir/myVM/"

$vm = Get-VM <VM-name> | Get-View
$vm.ReconfigVM($vmConfigSpec)

And to set it back to the default value you have to do it with an empty string ("") not with a dot (".")

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Files = New-Object VMware.Vim.VirtualMachineFileInfo
$vmConfigSpec.Files.snapshotDirectory = ""

$vm = Get-VM <VM-name> | Get-View
$vm.ReconfigVM($vmConfigSpec)


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

0 Kudos
jsouthwell
Contributor
Contributor
Jump to solution

Setting to an empty string works, but I am getting an error when putting in the path information:

I tried with an ending slash and without an ending slash. I'm missing something simple.

Exception calling "ReconfigVM" with "1" argument(s): "Invalid datastore path '/vmfs/volumes/2bca8df0-37eb5f60/MyVM/'."

At :line:19 char:14

+ $vm.ReconfigVM &lt;&lt;&lt;&lt; ($vmConfigSpec)

Exception calling "ReconfigVM" with "1" argument(s): "Invalid datastore path '/vmfs/volumes/2bca8df0-37eb5f60/CHSCA2'."

At :line:19 char:14

+ $vm.ReconfigVM &lt;&lt;&lt;&lt; ($vmConfigSpec)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Perhaps try a path with this syntax:

$vmConfigSpec.Files.snapshotDirectory = "[vmfsname] /SnapDir"

where "vmfsname" is the name you have given to the datastore,

and "Snapdir" is a directory in the root of that datastore.

Also note that there is a blank between the closing square bracket and the forward slash.


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

0 Kudos