VMware Cloud Community
Troy_Clavell
Immortal
Immortal
Jump to solution

Set-VMHostAdvancedConfiguration

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
16 Replies
LucD
Leadership
Leadership
Jump to solution

Nothing wrong with that code afaik, I'm afraid you hit a bug.


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

Troy_Clavell
Immortal
Immortal
Jump to solution

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.

0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

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

Troy_Clavell
Immortal
Immortal
Jump to solution

Thank you Yavor!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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

0 Kudos
a_p_
Leadership
Leadership
Jump to solution

Only a thought. Does the old scratch location still exist or has it already been removed?

see http://kb.vmware.com/kb/1026453

André

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

even if i manually create a scratch directory on /vmfs/volumes/<esxihost-local>/, the code still errors.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Troy_Clavell
Immortal
Immortal
Jump to solution

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!!!!

0 Kudos
yboychev
Hot Shot
Hot Shot
Jump to solution

Glad, this has been resolved (with no bug from PowerCLI)

-Yavor

0 Kudos
BrentCocjhran
Contributor
Contributor
Jump to solution

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

0 Kudos
BrentCocjhran
Contributor
Contributor
Jump to solution

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

0 Kudos