Hi There,
I know the options available for this command are:
WithVM
Inherit
InHostdatastore
But is there a way i can specify a specific datastore? In our environment we have specific datastores for certain types of virtual machines so none of the above options appear to do what i want.
Many Thanks
Mr G
The ReconfigVM method is only available on the VirtualMachine object. You have a string in the $objItem variable.
That works for the Shutdown-VMGuest cmdlet because it accepts Object By Name (OBN).
But the ReconfigVM method is only available on the VirtualMachine object, which you can reach via the Extensiondata property of the VirtualMachineImpl object.
The loop should look like this
...
foreach ($objitem in Get-VM $vm)
{
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
$vmConfigSpec.extraconfig[0].Key=$key
$vmConfigSpec.extraconfig[0].Value=$value
$objitem.Extensiondata.ReconfigVM($vmConfigSpec)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Afaik, you have to specify the swap datastore, provided you select the Inhostdatastore option, with the Set-VMHost cmdlet.
Set-VMHost -VMHost $esx -VMSwapfileDatastore $ds
I don't think you can specify individual datastores per VM.
It's for all VMs running on a specific host.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thats pretty much what i thought. I'm still a powershell novice but is it possible to maybe set this via the .vmx file instead then? i.e. have powershell make a line entry in this file?
Regards
Mr G
Afaik there is no .vmx entry for this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have just found a command called set-tkevmx but appears to be from some VI Toolkit Community Extension.
Will do some more research and post the comnpleted script if all goes well. Hopefully somebody else out there can benefit from it.
I have started to piece together a script from bits i've seen online but i can't get the last bit to work (Setting the actual vswp datastore). I keep getting an error message saying "Method invocation failed because [System.String] doesn't contain a method named 'ReconfigVM'. Can anybody advise? I have been looking at this all weekend and going crazy :smileysilly:.
#Script to set vSWP directory on specific virtual machines. 1st Provide a list of virtual machines via text file. Script will first attempt
#to power down virtual machines. Script will wait for x minutes for the vm to shut down then set the vSWP directory.
cls
$creds = Get-Credential
#Connect to vCenter. Change to your vCenter
Connect-VIServer ukvctest.misys.global.ad -Credential $creds
#Specify the path of your text file with system names here.
$vm = get-content "C:\Script Input\vm1.txt"
#Attempt to shutdown virtual machine. VMWare Tools must be installed in guest.
foreach ($objitem in $vm)
{
Write-Host "Shutting down system" $objitem
Shutdown-VMGuest -VM $objitem -Confirm:$false -ErrorAction SilentlyContinue
}
sleep -Seconds 180
##########################################################################################################################################
# This section will set each virtual machines .vSWP directory #
##########################################################################################################################################
$key = "sched.swap.dir"
$value = "/vmfs/volumes/f2as01_nfs_esxs01"
foreach ($objitem in $vm)
{
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
$vmConfigSpec.extraconfig[0].Key=$key
$vmConfigSpec.extraconfig[0].Value=$value
$objitem.ReconfigVM($vmConfigSpec)
}
The ReconfigVM method is only available on the VirtualMachine object. You have a string in the $objItem variable.
That works for the Shutdown-VMGuest cmdlet because it accepts Object By Name (OBN).
But the ReconfigVM method is only available on the VirtualMachine object, which you can reach via the Extensiondata property of the VirtualMachineImpl object.
The loop should look like this
...
foreach ($objitem in Get-VM $vm)
{
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
$vmConfigSpec.extraconfig[0].Key=$key
$vmConfigSpec.extraconfig[0].Value=$value
$objitem.Extensiondata.ReconfigVM($vmConfigSpec)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are a legend! Thank you very much for your help and swift responces. I finally managed to get this working Think i owe you a beer!
Regards
Mr G