Blog Home  Home |  Breeze Home RSS 2.0 Atom 1.0 CDF  
SCAREY Sharepoint Blog - April, 2009
Shannon - Breeze Training
# Tuesday, April 14, 2009

WOW!!!!! SharePoint designer is free. http://blogs.msdn.com/sharepoint/archive/2009/04/02/sharepoint-designer-available-as-a-free-download.aspx I think that MS has really hit the nail on the head with this decision :) In many classes that I run, teaching many students, Decision Makers, Designers, End Users etc I have found that this is a huge stumbling block from so many people. My business bought SharePoint but don't want to pay for the designer is something I hear way too often. Good job Microsoft, this will certainly encourage much more SharePoint customisations

Tuesday, April 14, 2009 12:47:19 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [0]    | 
# Saturday, April 11, 2009

Hi,

I have had the task of having to start and stop virtual machines in Windows Server 2008 Core without the use of Hyper-V Manager or VMM.

It is possible to start and stop the machines if you only have access to the command prompt through the use of WMI.

I have hacked together a script file that can start/stop/list what virtual machines are available and their current state

Instructions

download the file  VMControl.vbs (2.77 KB)

run VMControl.vbs with the following arguments

eg. "VMControl.vbs /list"

"/list" = list all VM's and their state
"/start virtualMachineName" = starts the the virtual machine
"/stop virtualMachineName" = stops the virtual machine
"/startAll" = starts all virtual machines on the host providing there is enough resources
"/stopAll" = stops all virtual machines on the host
"/help" = help information

Here is the code for it

*nb you may have to run this with admin privileges

Option Explicit 
 
'Setup the variables
Dim WMIService
Dim VMList
Dim Hostname
Dim VMName
Dim VMAction
Dim compareType
Dim HOST
Dim VM
Dim VMStatus
Dim AllVMs
 
'Used to get all machines or just one
compareType = "="
 
'gets and sets the host name
Set HOST = WScript.CreateObject("WScript.Network")
 
'Get instance of 'virtualization' WMI service on the local computer
Set WMIService = GetObject("winmgmts:\\.\root\virtualization") 
 
'Get the arguments from the user input and go to the appropriate sub
if wscript.Arguments.count > 0 then
    Select case WScript.Arguments.Item(0)
        case "/start"
            VMName = WScript.Arguments.Item(1)
            VMAction = 2
            compareType = "="
            modifyVM
        case "/stop"
            VMName = WScript.Arguments.Item(1)
            VMAction = 3
            compareType = "="
            modifyVM
        case "/startAll"
            VMName = HOST.ComputerName
            VMAction = 2
            compareType = "!="
            modifyVM
        case "/stopAll"
            VMName = HOST.ComputerName
            VMAction = 3
            compareType = "!="
            modifyVM
        case "/list"
            VMName = HOST.ComputerName
            compareType = "!="
            listVMs
        case "?","/?","-?","help","Help","/help","/Help"
            helpMsg
        case else
            helpMsg
    end select
else 
    helpMsg
end if
 
'Message to display when incorrect input or recived help switch
sub helpMsg
    AllVMs = "usage VMControl.vbs" 
& VBCr & VBCr & "/start <VM Name> - Starts the Virtual Machine" 
& VBCr & "/stop <VM Name> - Stops the Virtual Machine" 
& VBCr & "/startAll - Start all Virtual Machines" 
& VBCr & "/stopAll - Stop All Virtual Machines" 
& VBCr & "/list - List All Virtual Machines" 
end sub
 
'used to turn the VM on or off or saved
sub modifyVM
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem 
WHERE ElementName" & compareType & "'" & VMName &"'") 
 
    For Each VM In VMList
        VM.RequestStateChange(VMAction)          
        select case VMAction
            case 3 VMStatus = "stopped"
            case 2 VMStatus = "running"
            case 32769 VMStatus = "saved"
        end select
            AllVMs = VM.ElementName & " is " & VMStatus
    next
end sub
 
'used to get and display the VM's
sub listVMs
    Set VMList = WMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem 
WHERE ElementName" & compareType & "'" & VMName &"'") 
 
    For Each VM In VMList
        select case VM.EnabledState
            case 3 VMStatus = "stopped"
            case 2 VMStatus = "running"
            case 32769 VMStatus = "saved"
        end select
        AllVMs = AllVMs + VM.ElementName & " is " & VMStatus  & VBCr
    next
end sub
 
'Display a message of what happened or a help message
wscript.echo AllVMs

VMControl.vbs (2.77 KB)

Saturday, April 11, 2009 4:14:41 PM (AUS Eastern Standard Time, UTC+10:00)  #    Comments [1]    | 
Copyright © 2010 Breeze Training. All rights reserved.