Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Virtual Server

Vista - Hyper-v and Powershell

Reply
 
Old 02-09-2009   #1 (permalink)
Colin Bruce


 
 

Hyper-v and Powershell

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
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
Reply

Thread Tools


Similar Threads
Thread Forum
Hyper-V vs Full Win2008 Hyper-V Virtual Server
Hyper-V standalone vs Hyper-V windows 2008 Core Virtual Server
Cannot manage an Hyper-V on Core from a full installed W2K8 with Hyper-V... Virtual Server
Powershell, WMI and Hyper-V - Oh My PowerShell
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46