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

Vista - Powershell, WMI and Hyper-V - Oh My

Reply
 
Old 05-22-2008   #1 (permalink)
Rorschach


 
 

Powershell, WMI and Hyper-V - Oh My

Hi guys!

I am trying to work out ways to automate the provisioning of virtual
machines under hyper-v.

If I do the following:

$var1 = get-wmiobject -namespace root\virtualization
Msvm_VirtualSystemManagementService
$createnewvm = $var1.DefineVirtualSystem()

…it works fine.

So why cant I call the DefineVirtualMachine method in a single gwmi command
like this:

gwmi -namespace root\virtualization
Msvm_VirtualSystemManagementService.DefineVirtualSystem()

The detailed help for get-wmiobject seems to suggest it can be done in this
way:

-------------------------- EXAMPLE 5 --------------------------

C:\PS>(get-wmiobject win32_service -filter "name='alerter'").StopService()

This command stops the Alerter service. It calls the StopService method of
the win32_service WMI class.


Am I missing something?

Thanks guys.


My System SpecsSystem Spec
Old 05-22-2008   #2 (permalink)
Hal Rottenberg


 
 

Re: Powershell, WMI and Hyper-V - Oh My

Rorschach wrote:
Quote:

> So why cant I call the DefineVirtualMachine method in a single gwmi command
> like this:
>
> gwmi -namespace root\virtualization
> Msvm_VirtualSystemManagementService.DefineVirtualSystem()
>
> The detailed help for get-wmiobject seems to suggest it can be done in this
> way:
>
> -------------------------- EXAMPLE 5 --------------------------
>
> C:\PS>(get-wmiobject win32_service -filter "name='alerter'").StopService()
Quote:

> Am I missing something?
Yup! Look again--you need those parentheses to tell powershell to execute
what's inside them before trying to access a member.


--
Author, Tech Prosaic blog (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Old 05-22-2008   #3 (permalink)
RichS [MVP]


 
 

Re: Powershell, WMI and Hyper-V - Oh My

There is a good series of posts on PowerShell and Hyper-V at
http://dungkhoang.spaces.live.com/



--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Hal Rottenberg" wrote:
Quote:

> Rorschach wrote:
Quote:

> > So why cant I call the DefineVirtualMachine method in a single gwmi command
> > like this:
> >
> > gwmi -namespace root\virtualization
> > Msvm_VirtualSystemManagementService.DefineVirtualSystem()
> >
> > The detailed help for get-wmiobject seems to suggest it can be done in this
> > way:
> >
> > -------------------------- EXAMPLE 5 --------------------------
> >
> > C:\PS>(get-wmiobject win32_service -filter "name='alerter'").StopService()
>
Quote:

> > Am I missing something?
>
> Yup! Look again--you need those parentheses to tell powershell to execute
> what's inside them before trying to access a member.
>
>
> --
> Author, Tech Prosaic blog (http://halr9000.com)
> Webmaster, Psi (http://psi-im.org)
> Community Director, PowerShellCommunity.org
> Co-host, PowerScripting Podcast (http://powerscripting.net)
>
My System SpecsSystem Spec
Old 05-23-2008   #4 (permalink)
Hal Rottenberg


 
 

Re: Powershell, WMI and Hyper-V - Oh My

Rorschach wrote:
Quote:

> WMI is new to me but I grasp that
> a namespace is a collection or grouping of classes, that classes represent
> given manageable components and that methods represent practical functions of
> a class.
Another thing to add is that classes are composed of members. Members include
methods and properties.
Quote:

> (get-wmi –namespace\virtualization Msvm_VirtualSystemManagementService).
> DefineVirtualSystem()
Save yourself some typing and define a variable for this WMI object.

$vmgmt = get-wmi –namespace\virtualization Msvm_VirtualSystemManagementService
Quote:

> So that gave me a blank virtual machine under Hyper-V... I’m curious as to
> the parameters for the DefineVirtualSystem method.
I think you found the MSDN page but for quick peeks you can do this in
powershell. Learn the Get-Member and Get-Command cmdlets.

ps > $disks = gwmi Win32_LogicalDisk
ps > $disks | Get-Member -MemberType method
<snip>
ps > $disks | Get-Member chkdsk | format-list

TypeName : System.Management.ManagementObject#root\cimv2\Win32_LogicalDisk
Name : Chkdsk
MemberType : Method
Definition : System.Management.ManagementBaseObject Chkdsk(System.Boolean
FixErrors, System.Boolean VigorousIndexCheck, System.Boolean SkipFolderCycle,
System.Boolean ForceDismount, System.Boolean RecoverBadSectors,
System.Boolean OkToRunAtBootUp)
Quote:

> Is there a simpler way of changing the resource allocation for CPU, RAM
> etc? Following this example, I am a bit lost after the $VMSettingData
> variable is defined.
Me too. I don't know hyper-V well (yet), got my head deep into ESX at the
moment. However, if you grab System Center Virtual Machine Manager 2008 (SCVMM)
it comes with cmdlets to do all of this stuff I believe. You can download the
beta for free now:

http://www.microsoft.com/systemcente...m/default.mspx
Quote:

> Apologies for my stupidity, I will eventually get to grips with this. The
> first few days are always the hardest
The WMI method as explained in your post is actually pretty complex. Don't feel
bad about not immediately getting it! It is probably worth your time to mess
with SCVMM.


--
Author, Tech Prosaic blog (http://halr9000.com)
Webmaster, Psi (http://psi-im.org)
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast (http://powerscripting.net)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Hyper-v and Powershell Virtual Server
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 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