Error: The specified parameter 'Datastore' expects a single value creating VM via powershell

New-VM : 9/13/2012 10:03:28 AM    New-VM        The specified parameter 'Datastore' expects a single value, but your name criteria 'SAN03_iSCSI_06' corresponds to multiple values.

At C:\script\CreateVM206.ps1:15 char:11
+     New-VM <<<<  -Name $line.Name -VMHost $line.ESX -Template $templt -Datastore "SAN03_iSCSI_06" -OSCustomizationSpec $custtemp

    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop]:List`1) [New-VM], VimException
    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResultsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
New-VM : 9/13/2012 10:03:28 AM    New-VM        StorageResource parameter: Could not find any of the objects specified by name.

At C:\script\CreateVM206.ps1:15 char:11
+     New-VM <<<<  -Name $line.Name -VMHost $line.ESX -Template $templt -Datastore "SAN03_iSCSI_06" -OSCustomizationSpec $custtemp

    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...ource Datastore:RuntimePropertyInfo) [New-VM], ObnRecordProcessingFailedException
    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ObjectNotFoundCritical,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM


Yo tengo el siguiente script


$host1="h206.test.lab"
$hostds="SAN03_iSCSI_06"
$templt="Windows Server 2003 ENT SP2 (32-bit) - Latest (ESXi 5.0)"
$custtemp="Base ENG LAB SPEC_Windows Server 2003 - 32-Bit (Latest & R2)"

$sPath = "MachineList206.csv"
$dataCSV = Import-csv -path $sPath

foreach($line in $dataCSV)
{
    New-VM -Name $line.Name -VMHost $line.ESX -Template $templt -Datastore $ds -OSCustomizationSpec $custtemp
}


y lo que fue el problema, es que tenia dos Datastores con el mismo nombre en diferentes CLTs.. estaba usando el mismo disco para diferentes CLTs... no es buena practica :P....

Solucion

$host1="h206.test.lab"
$hostds="SAN03_iSCSI_06"
$templt="Windows Server 2003 ENT SP2 (32-bit) - Latest (ESXi 5.0)"
$custtemp="Base ENG LAB SPEC_Windows Server 2003 - 32-Bit (Latest & R2)"

$sPath = "MachineList206.csv"
$dataCSV = Import-csv -path $sPath

$esx = Get-VmHost $host1
$ds = $esx | Get-Datastore $hostds

foreach($line in $dataCSV)
{
    New-VM -Name $line.Name -VMHost $line.ESX -Template $templt -Datastore $ds -OSCustomizationSpec $custtemp
}

Comentarios