VMware Cloud Community
drwoodberry
Contributor
Contributor
Jump to solution

Creating new VM's with DPM

I currently have DPM running on my cluster. I have a script that will automatically create VM's and deploy them for me. However, sometimes the placement of the VM is on a host that is in standby and the script fails. How can I make sure that the script only chooses a host that is powered on? I have the -DrsAutomationLevel set to "FullyAutomated" in my script. The code I am using below is what creates the VM.

$vm= New-VM -Name $Server_Name -NumCPU 1 -DiskMB 40960 -DrsAutomationLevel FullyAutomated -MemoryMB 2048 -GuestID "winNetEnterpriseGuest" -CD:$true -Datastore $datastore -VMHost $vmhost

I am not sure what the issue is.

Reply
0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, drwoodberry-

You can handle this by first getting a host that is in a Connected state, then use that host for the -VMHost parameter to New-VM.  So, like:

## get a VMHost that is connected
$hostToUse = Get-Cluster myCluster | Get-VMHost | ?{$_.ConnectionState -eq "Connected"} | Get-Random
New-VM -Name ..<snip>.. -VMHost $hostToUse

Enjoy.

View solution in original post

Reply
0 Kudos
2 Replies
mattboren
Expert
Expert
Jump to solution

Hello, drwoodberry-

You can handle this by first getting a host that is in a Connected state, then use that host for the -VMHost parameter to New-VM.  So, like:

## get a VMHost that is connected
$hostToUse = Get-Cluster myCluster | Get-VMHost | ?{$_.ConnectionState -eq "Connected"} | Get-Random
New-VM -Name ..<snip>.. -VMHost $hostToUse

Enjoy.

Reply
0 Kudos
drwoodberry
Contributor
Contributor
Jump to solution

Thanks so much with your help on this!

Reply
0 Kudos