VMware Cloud Community
terencewklau
Enthusiast
Enthusiast
Jump to solution

ExpandVmfsDatastore Query

Hi,

I'm using the following code from LucD to expand a datastore:

$Datastore = Get-Datastore -Name "Datastore Name"

$ESXi = Get-View -Id ($Datastore.ExtensionData.Host |Select-Object -last 1 | Select -ExpandProperty Key)

$DatastoreSystem = Get-View -Id $ESXi.ConfigManager.DatastoreSystem

$ExpandOptions = $DatastoreSystem.QueryVmfsDatastoreExpandOptions($Datastore.ExtensionData.MoRef)

$DatastoreSystem.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef,$ExpandOptions.spec)

The above code is part of a main script that first expands the volume on the SAN, then executes the above code to expand the corresponding datastore in vcenter.  The main script fails with the following error:

Exception calling "ExpandVmfsDatastore" with "2" argument(s): "

Required parameter spec is missing

while parsing call information for method ExpandVmfsDatastore

If I just execute that part of the code in the main script later, it successfully expands the datastore. 

If I modify the code to add [0] as such ...

DatastoreSystem.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef,$ExpandOptions[0].spec)

... it also succeeds when the main script is run.

Just trying to understand the mechanics behind this process and why it fails initially.

Thanks.

Reply
0 Kudos
1 Solution

Accepted Solutions
terencewklau
Enthusiast
Enthusiast
Jump to solution

OK, looks like a timing issue.  $ExpandOptions returns an empty value, hence the last line of code does not work:

$DatastoreSystem.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef,$ExpandOptions.spec)

I've inserted a Do .. Until loop to check if $ExpandOptions is $null or not, and exit the loop if its not.

Cheers.

View solution in original post

Reply
0 Kudos
2 Replies
terencewklau
Enthusiast
Enthusiast
Jump to solution

Actually, scratch that [0] comment.  Running with that modification has also brought up the same error.

Running that part of the code a 2nd time succeeds.  Perhaps I need to add a delay like Start-Sleep -Seconds 10?

Any suggestions would be much appreciated.

Reply
0 Kudos
terencewklau
Enthusiast
Enthusiast
Jump to solution

OK, looks like a timing issue.  $ExpandOptions returns an empty value, hence the last line of code does not work:

$DatastoreSystem.ExpandVmfsDatastore($Datastore.ExtensionData.MoRef,$ExpandOptions.spec)

I've inserted a Do .. Until loop to check if $ExpandOptions is $null or not, and exit the loop if its not.

Cheers.

Reply
0 Kudos