## SQL Awesomesauce

### Start daily programs – More n00bz fun with #Powershell!

When I get in to work in the morning, I like a good cup of coffee waiting for me, a neck rub, and all my favorite programs open and waiting for me.  Since the first two seem out of the question, I focus on the third.

I’ve automated my start-of-day set of programs before by other means, but it’s awfully fun to see how PowerShell does it. So I did.

First, the PowerShell itself:

## Open Outlook ## # From script on http://stackoverflow.com/questions/3675533/powershell-to-open-outlook-make-visible # $outlook = new-object -com Outlook.Application$namespace = $outlook.GetNamespace("MAPI")$folder = $namespace.GetDefaultFolder("olFolderInbox")$explorer = $folder.GetExplorer()$explorer.Display()

## Open IE with several tabs ## #Modified from script on http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/9d003109-0903-414b-a635-ca2a9c485381/  # $ie = New-Object -ComObject InternetExplorer.Application$ie.Navigate2("about:Tabs",0x1000) $ie.Navigate2(https://myemail.com/)$ie.Navigate2("www.twitter.com",0x1000) $ie.Visible =$true

## Open SSMS ## # Inspired by http://technet.microsoft.com/en-us/library/ee176882.aspx  # Invoke-Item c:\temp\blank.sql

## Open a Word document ## #Modified from script on http://powershellscripts.blogspot.com/2007/02/convert-or-export-word-documents-to-pdf.html  # $word = new-object -ComObject "word.application"$doc = \$word.documents.open("c:\path\to\My Documents\Status.doc")

#Note: This script will only finish after SSMS receives the required authentication #

A couple of note: Clearly, I got all these scripts from digging around on Google, and some playing with Powershell Help. I like that I can open multiple tabs in IE; I leave one tab blank for Pandora, which would start playing automatically if I started it with this…and I don’t want music playing from my computer without me here.  I didn’t find an easy way to just open SSMS - I’m sure somebody will provide me the answer in Comments below – so I just opened a blank SQL file to do the trick.

Next, I created a BAT file with the PowerShell command powershell -command “& ‘c:\command\Open_My_Programs.ps1′ “  I saved this BAT file and the POSH file in c:\command\

Finally, I scheduled this to run right before I start my work day, using Windows Task Scheduler (see the Control Panel).  The scheduled task uses a command prompt, and I used advanced options to change the command to C:\WINDOWS\system32\cmd.exe /C “c:\command\Open_My_Programs.bat” and to kill the process if it runs for 90 minutes. (If I”m not at the office to log into SSMS, no point it letting the POSH script hang).

I haven’t tested this yet (how’s that for lazy blogging?), but as I understand it you kinda have to put the Powershell call in a batch file, because of the double quotes.

So there you go, a quick, dirty, and fun way to feel like the rock star IT guy you know you are.

By-the-by, I’m reading through Learn Windows PowerShell in a Month of Lunches by Don Jones (link goes to my review on ITBookworm.com), and I HIGHLY recommend it!

Happy days,
Jen McCown
http://www.MidnightDBA.com/Jen