SeriousMike
Contributor
Contributor

Set-AdvancedSetting returns "InvalidArgument" when setting ScratchLocation

Jump to solution

Hi everyone,

it's my first post here because usually LucD already solved all my issues upfront ๐Ÿ˜‰

I'm trying to set the ConfiguredScratchLocation via PowerCLI with the following lines:

# $ScratchDS contains the Datastore name
$Datastore = Get-Datastore $ScratchDS
New-DatastoreDrive -Datastore $Datastore -name "temp-datastore-scratch"

# $VMHostShort contains the hosts name
$ScratchFolder = ".locker-" + $VMHostShort
$NewScratchFolder = "temp-datastore-scratch:\$ScratchFolder"

if(-not (Test-Path -Path $NewScratchFolder)) {
    New-Item -ItemType Directory -Path $NewScratchFolder
}

# ScratchID contains the datastores ID
$NewScratchPath = "/vmfs/volumes/$ScratchID/$scratchFolder"
$CurrentScratchPath = Get-VMHost $VMHost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation"
if($CurrentScratchPath.Value -ne $NewScratchPath) {
    $CurrentScratchPath | Set-AdvancedSetting -Value $NewScratchPath -Confirm:$false
}

 

I used LucD's script as a base https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Set-Scratch-Location/m-p/2217154 

However for some reason it doesn't work. All I get is "InvalidArgument"

Set-AdvancedSetting : 20.06.2022 12:13:27       Set-AdvancedSetting             A specified parameter was not correct: 
In C:\privatePathToTheScript\Initialize-ESXiBasicSetup.ps1:89 Character:27
+ ... ratchPath | Set-AdvancedSetting -Value $NewScratchPath -Confirm:$fals ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-AdvancedSetting], InvalidArgument
    + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_GetVmHostAdvancedConfiguration_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands. 
   SetAdvancedSetting

I also ran the command directly without the variables with the same result.

Any recommendations?

Greetings

Mike

0 Kudos
1 Solution

Accepted Solutions
SeriousMike
Contributor
Contributor

ok, found the issue...

It's a brand new server (therefore the setup script) and the datastore is not yet known to the ESXi.

The script can create the folder but the host cannot see it yet...

Thanks anyways for the shortcut to the datastore ID!

View solution in original post

0 Kudos
8 Replies
mpeneva
VMware Employee
VMware Employee

Hi,

Please, could you check the value of $CurrentScratchPath ? Is it a single value or an array ?

 

SeriousMike
Contributor
Contributor

Hi mpenvea

it's a single entry:

Name                 Value                Type                 Description
----                 -----                ----                 -----------
ScratchConfig.Con... /vmfs/volumes/62b... VMHost
0 Kudos
mpeneva
VMware Employee
VMware Employee

Hi Mike,

Here is how I did the successful invocation:

(Get-AdvancedSetting -Entity (Get-VMHost $VMHost) -Name "ScratchConfig.ConfiguredScratchLocation") | Set-AdvancedSetting -Value $newValue -Confirm:$false

I've used the pipeline input to the cmdlet in that way.

Maya

 

Tags (1)
SeriousMike
Contributor
Contributor

Hi Maya,

just copied your line and still get the same error.

What's the content of $newValue in your case? A string?

0 Kudos
LucD
Leadership
Leadership

Your code works for me.
What did you populate $ScratchId with?
Is that the value from $Datastore.ExtensionData.Info.Url.split('/')[-2]


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

mpeneva
VMware Employee
VMware Employee

Oh, sorry that's my current config scratch value...I didn't want to make any changes to my local configuration.

You change it to yours ๐Ÿ™‚

 

Maya

0 Kudos
SeriousMike
Contributor
Contributor

Hi LucD

Yes - $ScratchID has the same content as $Datastore.ExtensionData.Info.Url.split('/')[-2]

I also see the folder in the vSphere web client. And Test-Path returns true.

0 Kudos
SeriousMike
Contributor
Contributor

ok, found the issue...

It's a brand new server (therefore the setup script) and the datastore is not yet known to the ESXi.

The script can create the folder but the host cannot see it yet...

Thanks anyways for the shortcut to the datastore ID!

0 Kudos