質問

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.

役に立ちましたか?

解決

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top