New-HyperVVM (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/571"></script>download | new post
Uses WMI to create a new virtual machine
inspired by “The Virtual PC Guy” http://blogs.msdn.com/virtual_pc_guy/archive/2008/05/28/scripting-vm-creation-with-hyper-v.aspx
Added the ability to specify a location to store the Virtual Machine
Also added remote capability to create a VM on a remote HyperV Host
Andy Schneider, http://www.get-powershell.com
- function New-HyperVVM {
- param (
- [string]$Hypervhost = "localhost",
- [string]$Vm = "VM Courtesy of PowerShell",
- [string]$location = "C:\MyVirtualMachines\$vm"
- )
- $wmiClassString = "\\" + $Hypervhost + "\root\virtualization:Msvm_VirtualSystemGlobalSettingData"
- $wmiclass = [WMIClass]$wmiClassString
- $newVSGlobalSettingData = $wmiClass.CreateInstance()
- $newVSGlobalSettingData.psbase.Properties.Item("ExternalDataRoot").value = $location
- $newVSGlobalSettingData.psbase.Properties.Item("ElementName").value = $Vm
- $VSManagementService = gwmi MSVM_VirtualSystemManagementService -namespace "root\virtualization" -ComputerName $Hypervhost
- $GlobalSettings = $newVSGlobalSettingData.psbase.GetText(1)
- $VSManagementService.DefineVirtualSystem($GlobalSettings, $ResourceSettings)
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository