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