VMware Cloud Community
scriptermad
Enthusiast
Enthusiast
Jump to solution

New VM Creation error

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
scriptermad
Enthusiast
Enthusiast
Jump to solution

how can i check that???

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
snoopj
Enthusiast
Enthusiast
Jump to solution

Can echo Luc's mention about using a debugger.  Valuable tool when making a very long set of Powershell scripts.

--j