powershell

One of things you encounter when you start doing repeat presentations is the need to have your environment in a Consistent and Ready state every time.

We all know the rules after a while.  Don’t change your demo box.  Avoid altering your environment in any way prior to the demo.   Avoid Murphy’s law.

Well here’s something to help you out.   I wrote a simple Powershell script to fire up the Demo machines in a times manner, Get my Powerpoint on the screen and even start the Connections to “remotely view” the Virtual machines in Hyper-V.

First off, you need to goto http://pshyperv.codeplex.com/ and download the HyperV modules for Powershell.  If you’re running SCVMM you can use the modules from it if you choose, but not all of us are running a fully licensed copy of SCVMM on our Demo Hyper-V box Smile

Once the Hyper-V module is downloaded and installed things get a lot easier on your HyperV demo box.

So our first script is going

  • Launch Powerpoint with our provided Presentation
  • Start VMCONNECT.EXE and connect us up to our Child Partitions in Hyper-V
  • Start up one demo machine
  • Sleep
  • Start up the next demo machine

So why would I want a delay?  How about dependences?   The Domain Controller?  An SQL Server?   The point is you typically do start up your Demo environment in a particular order.

First off once you execute an

IMPORT-MODULE HYPERV

Execute a

GET-VM

and get the names of the Virtual Machines.  Once you have them, the rest of this is easy.

————– START-DEMOENV.PS1 ————————

# Import HyperV Management Modules from Codeplex
import-module hyperv

# Specify name of Powerpoint Presentation

$PPT=’c:\users\Administrator\Desktop\MyPowerpoint.pptx’

# Launch Powerpoint 2010 (32bit version)
# Just edit the Path and filename if you’re running a 64bit version instead or
# Previous version of Microsoft Office

& ‘C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.EXE’ $PPT

# Launch VMConnect.exe connecting to the computer ‘localhost’
# and Virtual Machine called ‘HYPERV-DC1’ and the Virtual Machine called
# HYPERV-CLIENT

& ‘c:\Program Files\Hyper-V\vmconnect.exe’ localhost HYPERV-DC1
& ‘c:\Program Files\Hyper-V\vmconnect.exe’ localhost HYPERV-CLIENT

# Start the Child partition in Hyper-V called HYPERV-DC1
Start-VM "HYPERV-DC1"

# Sleep for 3 minutes (180 seconds) before starting up the client machines or those
# Dependant on your Demo Active Directory

Start-Sleep -Seconds 180

# Start the next machine (or machines) depedant on the Demo Active Directory
# environment.  this computer is called “HYPERV-CLIENT”

Start-VM “HYPERV-CLIENT"

————– START-DEMOENV.PS1 ————————

Now to have this script launchable from the desktop, you just need to create a shortcut pointing to the script and with the execution policy set

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\Users\Administrator\Desktop\Start-DemoEnv.PS1 -executionpolicy ‘RemoteSigned’

 

The other script I have you may find handy is the one to undo all of this.   For each of these machines I have a single Snapshot created (always a good idea in a demo setup) to allow myself to rollback to a previous state.  So our next script will

  • Rollback to the original snapshot state of each of these machines.  The states are programmed originally to NOT startup automatically
  • Kill the Powerpoint presentation
  • Kill the Remote connections to the Child partitions in HyperV

 

————– END-DEMOENV.PS1 ————————

# Import HyperV Management Modules from Codeplex

Import-module HyperV

# Get Child Partition “HYPERV-DC1”, pull the Snapshot and Force a Restore

GET-VM "HYPERV-DC1" | Get-VMSnapshot | Restore-VMSnapshot –force

# Get Child Partition “HYPERV-CLIENT”, pull the Snapshot and Force a Restore

GET-VM "HYPERV-CLIENT" | Get-VMSnapshot | Restore-VMSnapshot –force

# GET VMCONNECT and POWERPNT – Shut them down

GET-PROCESS VMCONNECT | STOP-PROCESS
GET-PROCESS POWERPNT | STOP-PROCESS

————– END-DEMOENV.PS1 ————————

Like the previous script, we want a way to launch this with the execution policy set.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file C:\Users\Administrator\Desktop\End-DemoEnv.PS1 -executionpolicy ‘RemoteSigned’

 

You of course may not have your scripts under the “Administrator” folder on the Desktop or be called END-DEMOENV.PS1 but that’s something you can always choose Smile

The nice part I like is the ability to have some consistency when start up just before you present to an audience.   The neater part is to notice something else.  Powershell launched standard executables in that run.

The Power of Shell is in YOU

Sean
The Energized Tech

Advertisements