View Single Post
Old 03-04-2009   #2 (permalink)
Blake


 
 

Re: Hyper-v and Powershell

Have you seen this:

http://www.codeplex.com/PSHyperv


"Colin Bruce" <ccx004@xxxxxx-THIS-coventry.ac.uk.AND-THIS> wrote in message
news:B2EE4D95-A865-42C1-BD1D-DD1899627646@xxxxxx
Quote:

> Dear All,
>
> I hope this is the right group and apologies if it isn't.
>
> I need to create a number of Hyper-V Virtual Machines and I thought I
> would
> script it with Powershell. I thought that would be quicker than just
> creating
> them by hand. Ah well I'll know better next time. Anyway, I now have a
> script
> but only works once. When now VMs exist the script works but when I try to
> create a second or third VM it fails in various places. The code in each
> of
> the places is pretty much the same so I'll only quote a snippet. Here is
> the
> code to allocate the number or processors.
>
> $VProc = gwmi -namespace root\virtualization
> Msvm_VirtualSystemSettingDataComponent | where {$_.PartComponent -like
> "*processor*"}
> $Proc = gwmi -namespace root\virtualization Msvm_ProcessorSettingData |
> where {$_.__PATH -like $($VProc.PartComponent) }
> $Proc.VirtualQuantity = $NProcs
> $Result = $VSManagementService.ModifyVirtualSystemResources($NewVM_PATH,
> $Proc.psbase.getText(1))
>
> When I create the first VM it is fine but when I create a second one I
> get:
>
> Property 'VirtualQuantity' cannot be found on this object; make sure it
> exists
> and is settable.
> At E:\Shared\Hyper-V\Hyper-V Clone.ps1:264 char:7
> + $Proc.V <<<< irtualQuantity = $NProcs
> You cannot call a method on a null-valued expression.
> At E:\Shared\Hyper-V\Hyper-V Clone.ps1:265 char:94
> + $Result = $VSManagementService.ModifyVirtualSystemResources($NewVM_PATH,
> $Pro
> c.psbase.getText( <<<< 1))
>
> This has me beaten I'm afraid.
>
> Any advice will be appreciated.
> --
> Best wishes...
> Colin Bruce
> Coventry University

My System SpecsSystem Spec