Automation

 View Only
Expand all | Collapse all

Set-VMHostAdvancedConfiguration

Troy_Clavell

Troy_ClavellMar 17, 2011 06:25 PM

  • 1.  Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 05:48 PM

    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



  • 2.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:15 PM

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



  • 3.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:20 PM

    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.



  • 4.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:23 PM

    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



  • 5.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:25 PM

    Thank you Yavor!



  • 6.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:42 PM

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


  • 7.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 06:55 PM

    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



  • 8.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 07:00 PM

    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)


  • 9.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 07:07 PM

    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



  • 10.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 07:18 PM

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

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

    André



  • 11.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 07:34 PM

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



  • 12.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 07:40 PM

    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 ?



  • 13.  RE: Set-VMHostAdvancedConfiguration
    Best Answer

    Posted Mar 17, 2011 07:48 PM

    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



  • 14.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 17, 2011 08:05 PM

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



  • 15.  RE: Set-VMHostAdvancedConfiguration

    Posted Mar 18, 2011 01:40 PM

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

    -Yavor



  • 16.  RE: Set-VMHostAdvancedConfiguration

    Posted Jul 24, 2012 11:32 PM

    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



  • 17.  RE: Set-VMHostAdvancedConfiguration

    Posted Jul 25, 2012 08:31 PM

    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