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 - Shutdown and startup Hyper-V Virtual Machine via script

Reply
 
Old 11-07-2008   #1 (permalink)
FC


 
 

Shutdown and startup Hyper-V Virtual Machine via script

Hi,

I have tried some scripts for shutting down a virtual machine without success.

What I need is a command for shutting down and starting up a named virtual
machine in Hyper-V like:

Shutdown "SERVERNAME"
Startup "SERVERNAME"

Can it be that simple?


/FC

My System SpecsSystem Spec
Old 11-09-2008   #2 (permalink)
Paul Weterings


 
 

Re: Shutdown and startup Hyper-V Virtual Machine via script

FC wrote:
Quote:

> Hi,
>
> I have tried some scripts for shutting down a virtual machine without success.
>
> What I need is a command for shutting down and starting up a named virtual
> machine in Hyper-V like:
>
> Shutdown "SERVERNAME"
> Startup "SERVERNAME"
>
> Can it be that simple?
>
>
> /FC
what's wrong with shutdown -r -f -m machine-name?

starting up is another stoty.. haven't tried WOL on virtual machines yet.

Then again, you could simply try using WMI

Option Explicit



Dim WMIService

Dim VMList

Dim VMName



'Specify the name of the virtual machine that I want to start

VMName = "TestVM"



'Get instance of 'virtualization' WMI service on the local computer

Set WMIService = GetObject("winmgmts:\\.\root\virtualization")



'Query for the specific virtual machine that I want to start

Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem
WHERE ElementName='" & VMName & "'")



' Request a state change on the first VM that is returned

' 2 = start, 3 = stop and 32769 = save state

VMList.ItemIndex(0).RequestStateChange(2)



You can copy, adjust and save all these lines as a VBScript (e.g.
StartVM.vbs) by using notepad. And then you can run this VBScript.



--

/ ) Regards,
/ /_________
_|__|__) Paul Weterings
/ (O_) http://www.servercare.nl
__/ (O_)
____(O_)
My System SpecsSystem Spec
Old 01-28-2009   #3 (permalink)
Blake


 
 

Re: Shutdown and startup Hyper-V Virtual Machine via script

There is a powershell library you can use to leverage PS with Hyper-V -
that's what I'm doing:

http://www.codeplex.com/PSHyperv

Then I can issue thusly at the command line:

powershell.exe "& {. 'C:\test\hyperv.ps1';Start-VM CALMACIL}"
powershell.exe "& {. 'C:\test 1\hyperv.ps1';Suspend-VM CALMACIL}"

It currently throws a warning but the script DOES work in regards to
starting/stopping/pausing the VM.

Blake


"Paul Weterings" <Paul-nospam-@xxxxxx-dot-com> wrote in message
news:4917670b$0$14837$e4fe514c@xxxxxx
Quote:

> FC wrote:
Quote:

>> Hi,
>>
>> I have tried some scripts for shutting down a virtual machine without
>> success.
>>
>> What I need is a command for shutting down and starting up a named
>> virtual machine in Hyper-V like:
>>
>> Shutdown "SERVERNAME"
>> Startup "SERVERNAME"
>>
>> Can it be that simple?
>>
>>
>> /FC
> what's wrong with shutdown -r -f -m machine-name?
>
> starting up is another stoty.. haven't tried WOL on virtual machines yet.
>
> Then again, you could simply try using WMI
>
> Option Explicit
>
>
>
> Dim WMIService
>
> Dim VMList
>
> Dim VMName
>
>
>
> 'Specify the name of the virtual machine that I want to start
>
> VMName = "TestVM"
>
>
>
> 'Get instance of 'virtualization' WMI service on the local computer
>
> Set WMIService = GetObject("winmgmts:\\.\root\virtualization")
>
>
>
> 'Query for the specific virtual machine that I want to start
>
> Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem WHERE
> ElementName='" & VMName & "'")
>
>
>
> ' Request a state change on the first VM that is returned
>
> ' 2 = start, 3 = stop and 32769 = save state
>
> VMList.ItemIndex(0).RequestStateChange(2)
>
>
>
> You can copy, adjust and save all these lines as a VBScript (e.g.
> StartVM.vbs) by using notepad. And then you can run this VBScript.
>
>
>
> --
>
> / ) Regards,
> / /_________
> _|__|__) Paul Weterings
> / (O_) http://www.servercare.nl
> __/ (O_)
> ____(O_)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RE: System Center Virtual Machine Manager2007 & HYPER-V in 2008 CORE Virtual Server
Microsoft Hyper-V Server 2008 - create virtual machine Virtual Server
Moving Virtual Machine from Hyper-v to Virtual Server 2005 Virtual Server
Can we run ESX Server on a virtual machine that runs on Hyper V Virtual Server
Hyper V: virtual machine will not accept memory more than 4 GB Virtual Server


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