1

This question answers how to launch PowerShell from Windows Explorer.

I want to launch PowerShell from Windows Explorer with my TFS Shell Snap-In pre-loaded.

I created a batch file (RunPowerShell.bat) with this command** and put it in the System32 directory:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\tfshell.psc1" -noexit -command ". 'C:\Program Files (x86)\Microsoft Team Foundation Server 2010 Power Tools\TFSS

This works, but I'd like to do it with just typing "PowerShell" in the Windows Explorer address bar.

Is it possible to load this snapin from Windows Explorer just by typing "PowerShell"?

**The command shown above comes from the "Target" box of my PowerShell Console link in the menu option:

Enter image description here


UPDATE

Chris N put me in the right direction.

I had to do a few things to make it work, so I'll put them here:

Create and register the following registry file (*.reg) so that PowerShell would be aware of the TFS PowerShell DLL file:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell]
"PowerShellVersion"="2.0"
"Vendor"="Microsoft Corporation"
"Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft"
"DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"Version"="10.0.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2010 Power Tools"
"AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ModuleName"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2010 Power Tools\\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
"CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"

In Notepad, create a new file with the following command:

if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Microsoft.TeamFoundation.PowerShell
}

The IF statement prevents an error if I load from the link in the Windows Menu.

Then, save that file as this:

%windir%\system32\WindowsPowerShell\v1.0\profile.ps1

This will make the command run for all shells and all profiles on Windows; read the link in Chris's answer if you need a smaller scope.

Community
  • 1
  • 1
ray
  • 8,521
  • 7
  • 44
  • 58

1 Answers1

2

Read the great article Windows PowerShell Profiles on PowerShell profiles. Depending on the profile you setup, you can affect any instance started of PowerShell on that machine.

It should work to load the snap in from the following script (to affect ALL users and ALL shells):

%windir%\system32\WindowsPowerShell\v1.0\profile.ps1
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris N
  • 7,239
  • 1
  • 24
  • 27
  • Thanks Chris. I pretty got what I needed from that. The only issue I have is that the example that "applies to all users and all shells" does not work when I type "PowerShell" from the explorer menu. It works in this folder with this file though: D:\Users\Ray\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 Any thoughts there? – ray Jul 30 '12 at 15:15
  • If you go to the profile I mention in the answer, and add the line: Write-Host Hello from the default profile! , does it show up when you open the shell? – Chris N Jul 30 '12 at 15:17
  • It doesn't. I tried it with "profile.ps1" in that dir and then renamed it to "Microsoft.PowerShell_profile.ps1" (the same one in my profile that works and that did not work either. I totally could be missing something there, but it _looks_ like I did it right. – ray Jul 30 '12 at 15:25
  • 1
    It works for me on my machine in every shell. Just to verify, you opened up C:\Windows\System32\WindowsPowerShell\v1.0\ and made a new file there called profile.ps1 . If you go to notepad, choose file, open and then paste in: %windir%\system32\WindowsPowerShell\v1.0\profile.ps1 does it open up your script? – Chris N Jul 30 '12 at 15:27
  • Ok...creating it manually with Notepad made it work. I first tried to make PowerShell create it and then I tried to manually create with Notepad++. It wasn't working; maybe just not firing on all cylinders this morning. It's good to go now. Thanks so much for you help. – ray Jul 30 '12 at 15:35