We are trying to move our ESXi 4.1 scratch config to the local drive via PowerCLI. Has anyone done this successfully and can tell me what is wrong with the code below.
$ESXHost = "<esxhostname>"
Get-VMHost $ESXHost | Set-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/($ESXHost)-local/scratch"
error:
Set-VMHostAdvancedConfiguration : 3/17/2011 10:38:28 AM Set-VMHostAdvancedConfiguration A specified parameter was not correct.
At C:\Users\tclavell\AppData\Local\Temp\f8e3ef60-5223-4ec6-a0ad-1e46f1aaffad.ps1:3 char:54
+ Get-VMHost $ESXHost | Set-VMHostAdvancedConfiguration <<<< -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/($ESXHost)-local/
scratch"
+ CategoryInfo : NotSpecified: (:) [Set-VMHostAdvancedConfiguration], InvalidArgument
+ FullyQualifiedErrorId : Client20_MoServiceImpl_Invoke_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAdvancedConfiguration
version:
PowerCLI Version
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
Just tried again with the cmdlet and it works. No bug!
You have to give it a correct path
Set-VMHostAdvancedConfiguration -VMHost $esx -Name "ScratchConfig.ConfiguredScratchLocation" `
-Value "/vmfs/volumes/DS1"
and
Set-VMHostAdvancedConfiguration -VMHost $esx -Name "ScratchConfig.ConfiguredScratchLocation" `
-Value "/vmfs/volumes/DS1/Test"
both worked. Just have to make sure you pass a correct and existing path
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nothing wrong with that code afaik, I'm afraid you hit a bug.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
a bug, bummer! I'll report back if there is another way we can figure out how to make this work using PowerCLI. I'll see if my TAM can file a PR.
I'll take a look at that and try to repro in our test env. I'll take the corresponding action: file a bug or contact you for more info about your env if I'm not able to hit it.
Thanks for sharing,
Yavor, PowerCLI engineering team
Thank you Yavor!
As a temporary bypass you can use the SDK method directly
$ESXHost = "<esxhostname>" $esx = Get-VMHost $ESXHost
$optMgr = Get-View $esx.Extensiondata.ConfigManager.AdvancedOption $opt = New-Object VMware.Vim.OptionValue
$opt.Key = "ScratchConfig.ConfiguredScratchLocation"
$opt.Value = "/vmfs/volumes/($ESXHost)-local/scratch" $optMgr.UpdateOptions(@($opt))
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The SDK method errored for me as well. I think the below line may be part of the problem?
$optMgr = Get-View $esx.Extensiondata.ConfigManager.AdvancedOption
error:At C:\Users\tclavell\AppData\Local\Temp\5fbbab9d-653f-496b-9f86-06d9d8b1f701.ps1:8 char:22
+ $optMgr.UpdateOptions <<<< ($opt)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
You have to give an array of OptionValue objects as the parameter.
That's why I did
$optMgr.UpdateOptions(@($opt))
while the error message seems to say you did
$optMgr.UpdateOptions($opt)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
my apologies... I was playing around with the code and provided the wrong error. if I run it from CLI I get the below error
Exception calling "UpdateOptions" with "1" argument(s): "A specified parameter
was not correct.
"
At C:\scripts\scratch.ps1:9 char:22
+ $optMgr.UpdateOptions <<<< (@($opt))
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Only a thought. Does the old scratch location still exist or has it already been removed?
see http://kb.vmware.com/kb/1026453
André
even if i manually create a scratch directory on /vmfs/volumes/<esxihost-local>/, the code still errors.
When I tried with a non-existing folder I get the same message, when I give an existing folder it works.
Does that path work from the vSphere client ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just tried again with the cmdlet and it works. No bug!
You have to give it a correct path
Set-VMHostAdvancedConfiguration -VMHost $esx -Name "ScratchConfig.ConfiguredScratchLocation" `
-Value "/vmfs/volumes/DS1"
and
Set-VMHostAdvancedConfiguration -VMHost $esx -Name "ScratchConfig.ConfiguredScratchLocation" `
-Value "/vmfs/volumes/DS1/Test"
both worked. Just have to make sure you pass a correct and existing path
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Brilliant! Now I see where I messed up. Our new code looks like the below and works
$ESX = "<esxhost>"
Set-VMHostAdvancedConfiguration -VMHost $ESX -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/$ESX-local/scratch"
I see now the problem was from the beginning with using the ( )-local
Now I can sleep well tonight!!!!
Glad, this has been resolved (with no bug from PowerCLI)
-Yavor
I'm running this same command to as part of our host baseline. The last piece is creating the /scratch directory in the local datastore. How can I do that with PowerCLI?
Thx- Brent
I have it figured out now. In case anyone else stumbles on this thread with the same question:
#################
$localds = get-datastore -vmhost $_ *_local
new-psdrive -location $localds -name localds -psprovider vimdatastore -Root '\'
mkdir -Path localds:\ -name scratch
#################
Cheers!
Brent