Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Friday, October 05, 2012

How to start/stop Hyper-V machines with PowerShell

Being a Hyper-V fan, I try to keep all of my VM’s named and line up correctly.  The problem is that with so many versions of SharePoint, SQL, OS.  The management of those VM’s can get a bit tricky.  For instance, I have 3 SharePoint farms that I might need to run at one point or another.  The problem that I had, was that I wanted to start a farm or a set of vm’s with a single script.  Well, trying to start up all of your vm’s at once creates a problem when you try to start a SharePoint farm.

The dependencies for SharePoint is that the SQL server needs to be up and running as well as the Domain controller.  For the SQL Server to start, it needs the Domain controller to be up and running.  So somehow, you need to start the AD, wait for it to be up and running before starting the SQL, and then finally when both are running, then you can start your SharePoint server.  This sequence does not allow you to get a cup of coffee while all of the vm’s are starting.  You need to monitor the state of each server before  moving to the next one.

The workflow will be something like this:  AD –>  SQL –> SharePoint

Now, enter PowerShell.  With PowerShell, I have several scripts that will perform this workflow correctly.  If you are still running Windows Server 2008-R2 as your desktop machine (and who isn't, right?), you can download the Powershell Management Library for Hyper-V in Codeplex.  This module is necessary, even if you are running PowerShell v3.

hyperV

Here is my script to start up the VM machines.  Noticed that I’m using the HearBeatTimeOut.  This parameter waits for the OS to be up and running before the next command is executed!
Import-Module "C:\Program Files\modules\HyperV\HyperV.psd1"

start-vm "DemoAD" -HeartBeatTimeOut 300
start-vm "DemoSQL2008" -HeartBeatTimeOut 300
start-vm "DemoWFE1" -HeartBeatTimeOut 300

and the script to stop them.  It is always nice to use the reason parameter. This parameter is needed so that I don’t have to explain WHY it was shutdown when starting the VM’s.
Import-Module "C:\Program Files\modules\HyperV\HyperV.psd1"

shutdown-vm "DemoWFE1" -force -reason "end of day"
shutdown-vm "DemoSQL2008" -force -reason "end of day"
shutdown-vm "DemoAD" -force -reason "end of day"

now, where is that cup of coffee… :)

Thursday, October 02, 2008

DocTools not working

For one of the projects we are working on, we need to make sure our end user documentation matches correctly the template provided by the customer. I have started playing with one of the products that the Patterns and Practices at Microsoft is using to generate their documentation. Take a look at their package: http://www.codeplex.com/doctools

After going through all of the installation and pre-requisites.  I was ready to try the sample Word Document they provide.  Snag.!  

First thing I notice is that the sample scripts are looking for the Microsoft DocTools in the c:\program files\Microsoft DocTools.  Changing those scripts brought to my attention that the install program gives you the ability to specify the path on where to install the DocTools.  However, it will always install to the (x86) directory on my Vista x64.

The main error I was getting was:

PS C:\DocToolsDemo> .\HTML.cmd

C:\DocToolsDemo>PowerShell ConvertToHTML.ps1 ESBIntro.docx .\outputHTML """C:\Program Files (x86)\Microsoft DocTools\Document Converter\Formatting\MSDN2\xsl""" convertESBConfig.xml

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\DocToolsDemo

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         10/1/2008   9:10 AM            outputHTML

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\DocToolsDemo\outputHTML

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         10/1/2008   9:10 AM            html
Add-PSSnapin : No Windows PowerShell Snap-ins are available for version 1.
At C:\Program Files (x86)\Microsoft DocTools\Document Converter\ConverterLibrary.ps1:9 char:15
+         Add-PSSnapIn  <<<< ppConverter.Cmdlets

--Splitting: C:\DocToolsDemo\ESBIntro.docx
An Error Ocurred: The term 'Split-Document' is not recognized as a cmdlet,
function, operable program, or script file.Verify the term and try again.

PS C:\DocToolsDemo>

After doing all of the regular stuff (check PATH, re-install, start/stop program, google), I could not get this error to go away.

The problem seems to be with the OS I am running.  Since I am running a 64bit OS, I need to call the PowerShell that is on the c:\windows\syswow64 and not the one in the regular 32bit.  This is accomplish by running the one marked with the (x86)

image

Once I opened this one, ran the set-executionpolicy remotesigned command.  It ran and split the Word document successfully and generated my HTML help compile file.

image

One of those simple bugs that can waste a whole hour for you.!