VMware Cloud Community
SeriousMike
Contributor
Contributor
Jump to solution

Set-AdvancedSetting returns "InvalidArgument" when setting ScratchLocation

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

Reply
0 Kudos
1 Solution

Accepted Solutions
SeriousMike
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
8 Replies
mpeneva
VMware Employee
VMware Employee
Jump to solution

Hi,

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

 

SeriousMike
Contributor
Contributor
Jump to solution

Hi mpenvea

it's a single entry:

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

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
Jump to solution

Hi Maya,

just copied your line and still get the same error.

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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
Jump to solution

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

Reply
0 Kudos
SeriousMike
Contributor
Contributor
Jump to solution

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.

Reply
0 Kudos
SeriousMike
Contributor
Contributor
Jump to solution

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!

Reply
0 Kudos