Hi Guys
Here is script (part of )
$myhost = Get-VMHost -Location $cell_id ------$cell_id is an internal thing where two hosts reside, each with one local datastore
$Myhost1 = $myhost[0]
$Myhost2 = $myhost[1]
$myds = $myhost1 | Get-Datastore
$h1ds1 = $myds[0]
$h1ds2 = $myds[1]
$myds2 = $myhost2 | Get-Datastore
$h2ds1 = $myds2[0]
$h2ds2 = $myds2[1]
New-OSCustomizationSpec -Name $OSCostumSpec_SQL -OSType Windows -AdminPassword $VMPassword -TimeZone $TimeZone -ProductKey $WinProductKey_SQL -ChangeSid -OrgName $OrgName -NamingScheme Fixed -NamingPrefix $SQLVM.split(".")[0] -fullname Administrator -Workgroup WORKGROUP
New-OSCustomizationNicMapping -OSCustomizationSpec $OSCostumSpec_SQL -IpMode UseStaticIP -IPAddress $SQLVMIP -SubnetMask $VMSubnet -DefaultGateway $VMGefaultGateway -Dns $DNS,$DNSVCE -Position 1
New-VM -VMHost $Esxihost -Name $SQLVM -Datastore $h1ds2 -Template $SQL2008RTemplate -OSCustomizationSpec $OSCostumSpec_SQL
Get-VM -name $SQLVM | Set-VM -Version $VMVER -confirm:$false
Get-NetworkAdapter -VM $SQLVM | where {$_.Name -eq "Network adapter 2"} | Remove-NetworkAdapter -confirm:$false
Get-NetworkAdapter -VM $SQLVM | where {$_.Name -eq "Network adapter 1"} | Set-NetworkAdapter -NetworkName $MGMT -confirm:$false -StartConnected:$true
Remove-OSCustomizationSpec $OSCostumSpec_SQL -confirm:$false
Set-VM -VM $SQLVM -MemoryMB 8192 -NumCpu 4 -Description "vCenter DataBase Server" -confirm:$false
$SQLVM.ExtensionData.ReconfigVM_Task($CPU2)
The new vm creation is failing with this error
New-VM cannot validate arguement on parameter datastore . The arguement is null or empty , supply an arguement that is not null or empty and try again.
ANy idease?
Did you check there is anything in the variables $MyHost1, $MyHost2, $h1ds1, $h1ds2, $h2ds1, $h2ds2 ?
Seems that the datastore variables are empty (judging from the error message)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you check there is anything in the variables $MyHost1, $MyHost2, $h1ds1, $h1ds2, $h2ds1, $h2ds2 ?
Seems that the datastore variables are empty (judging from the error message)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
how can i check that???
The easiest way, just enter the variable(s) on a line by itself, it will display the content on the console
$myhost = Get-VMHost -Location $cell_id ------$cell_id is an internal thing where two hosts reside, each with one local datastore
$Myhost1 = $myhost[0]
$Myhost2 = $myhost[1]
$Myhost1
$Myhost2
$myds = $myhost1 | Get-Datastore
$h1ds1 = $myds[0]
$h1ds2 = $myds[1]
$myds2 = $myhost2 | Get-Datastore
$h2ds1 = $myds2[0]
$h2ds2 = $myds2[1]
$h1ds1
$h1ds2
$h2ds1
$h2ds2
An alternative, where you don't have to add any lines in the script, is to use an IDE with a debugger.
Then you would just need to set a breakpoint.
The ISE that is included with the latest PowerShell versions serves this task.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can echo Luc's mention about using a debugger. Valuable tool when making a very long set of Powershell scripts.
--j