Powershell & HyperV - Create a VM in a specific folder

Well, James O'Neill has updated his library on codeplex again, but there is still a function missing that I needed. In our environment we create multiple machines and I wanted a way to create them in a specific directory, now I know I could set the default location and then create it, but I prefer to just specify a path and go from there.

I started from Ben Armstrong's code at Virtual PC Guy's Weblog and then modified the code after the VM name is set to also specify the location of the folder it will be created in.

# Setthe VM name
$newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $VMName

# New code - Set Folder location
$VMFolder = "E:\DevVMs\"
$newVSGlobalSettingData.psbase.Properties.Item("ExternalDataRoot").value = $VMFolder + $VMName

It took a little while to find the correct property to set, and I don't think that ExternalDataRoot is particularly obvious but the documentation at MSDN was helpful. In the example above, it puts the VM files in E:\DevVMs\VMName.

For our scripts I then used the HyperV Library to configure the VM with CPUs, RAM, disks and network connections.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



 

Dilbert of the day