## Friday, July 20, 2012

### Launching Apps with PowerShell Functions

Launching of apps is much easier with windows 7 taskbar.  The "pin to taskbar" option when you right click any open software will pin the item to the taskbar.  I have lots of remote desktop sessions pinned on remote desktop connection. However, there are some situations where launching some softwares it is quicker through your keyboard than through the mouse.  AutoHotkey is very popular when you want to assign shortcut keys for launching apps and trigger some custom actions.  However, I have fallen in love with the PowerShell way of launching some of my favorite and most used apps on windows.   I have found it very useful and so I would like to share them with you.

Launch Remote Desktop Connections with PowerShell
Put this PS function in your PS profile and replace server10 with your server name in the following command and see remote desktop connection open up on its own.  For the first time, you will have to enter the password.  I love this very much.

function rmd {
param([string]$computername) & "C:\windows\system32\mstsc.exe" /v:$computername /fullscreen
}

PS> C:\>rmd server10

Suppose you had an error when you were working inside powershell and you had no idea what that error was and you thought that a Google search might result an answer.  At this point you don’t want to copy the error object or text and then open or switch to Google and type.  This function takes care of searching on Google for you.  It will search for the last error [$error[0]] encountered . Check this function out and if you like it then put it in your powershell profile. Replace the chrome.exe path with your path or it might be just replacing Goofy with your name. function Get-ErrorInfo & "C:\Users\Goofy\AppData\Local\Google\Chrome\Application\chrome.exe" https://www.google.com/search?q=$error[0].Exception
}

Let’s do some dumb mistake and try to search it on Google.

PS C:\> get-comand19

The term 'get-comand19' is not recognized as the name of a cmdlet, function, script file, or operable program. Check th
e spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:13
+ get-comand19 <<<<
+ CategoryInfo          : ObjectNotFound: (get-comand19:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

PS C:\> get-errorinfo

Just search on Google with PowerShell
If you observed the command carefully then you know how to search on Google through powershell.  Here is my simple function to search on Google.

function g {
param([string]$searchstring) & "C:\Users\Goofy\AppData\Local\Google\Chrome\Application\chrome.exe" https://www.google.com/search?q=$searchstring
}

Launch volume control pop-up with PowerShell
I have a bad habit of experimenting something in powershell (more on that later).  However, I found this link on superuser.com about open the volume control with a command.  Try this command “sndvol.exe –f” in run command window (open it by typing win+r) and you can see volume control but again when working in PowerShell I want to do it from PowerShell. Sweet little no brainer PS function.

function vol { & "C:\windows\system32\sndvol.exe" -f}

Hit vol and see volume control pop-up.  Use up and down arrow key to control vol (obviously).
Launch a Visual Studio solution with PowerShell
Start a visual studio solution from PowerShell.  Yes, I know that you can pin your most frequented items to task bar but I wanted to do it in powershell. I have created a small PowerShell function to start my daily project that I am working on. I don’t if people would find it useful or not but I do find it useful in my work life.

function vs {
param([string]$document) switch($document){
"pm"{
start "C:\sourcecode\dailyprojectIworkOn.sln"
}
}
}

Launch a word document with PowerShell
Ah! So easy once you know how the start cmd works right. Just put it in front of any document and it will open in relevant software for you. One of the things I have opened while working on a project is having a word document opened up.  It is like my live journal of that project.  Over a time my word document get very large and I have to do two things: 1) Open word doc 2) Scroll to the last page 3) Save it before exiting.  For two and and three I have created a word macro which will scroll the doc to the last page and save it for me before I exit.  Finally for launching that word document I do this.

function show{
param([string]$document) switch($document){
"pm" {
start "C:\project\projdoc.docm"
}
}
}
So you see I don't panic if the start menu is gone from windows 8.  I only have to remember the PowerShell way of launching apps.  If you have some other PowerShell functions that you put in your PowerShell profile then share with me in the comments sections.