Fixes to Get-HVDatastore() when multiple datastores are specified

`$Datastores` needs to be initialized as an empty array `@()` rather than `$null`.  Furthermore, if `$DsStroageOvercommit` is empty it is only initialised with a single element where there should be one element per datastore.  I've moved the test into the loop instead.
This commit is contained in:
mtelvers
2017-11-02 22:18:41 +00:00
parent c2f137c812
commit 5879c10003

View File

@@ -5039,15 +5039,16 @@ function Get-HVDatastore {
foreach ($ds in $datastoreNames) {
$datastoresSelected += ($datastoreInfoList | Where-Object { ($_.DatastoreData.Path -eq $ds) -or ($_.datastoredata.name -eq $ds) }).id
}
$Datastores = $null
if (! $DsStorageOvercommit) {
$DsStorageOvercommit += 'UNBOUNDED'
}
$Datastores = @()
$StorageOvercommitCnt = 0
foreach ($ds in $datastoresSelected) {
$myDatastores = New-Object VMware.Hv.DesktopVirtualCenterDatastoreSettings
$myDatastores.Datastore = $ds
$mydatastores.StorageOvercommit = $DsStorageOvercommit[$StorageOvercommitCnt]
if (! $DsStorageOvercommit) {
$mydatastores.StorageOvercommit = 'UNBOUNDED'
} else {
$mydatastores.StorageOvercommit = $DsStorageOvercommit[$StorageOvercommitCnt]
}
$Datastores += $myDatastores
$StorageOvercommitCnt++
}