2012-07-30 66 views
1

This question回答如何從Windows資源管理器啓動PowerShell。如何使用管理單元從Windows資源管理器啓動PowerShell

我想從Windows啓動PowerShell   Explorer,並預裝了我的TFS Shell Snap-In。

我創建一個批處理文件(RunPowerShell.bat)使用該命令**,並把它放在System32下目錄:

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 

這工作,但我想做到這一點的只需在Windows  資源管理器地址欄中輸入「PowerShell」即可。

是否可以通過鍵入「PowerShell」從Windows資源管理器加載該管理單元?

**上面顯示的命令來自於菜單選項我PowerShell控制檯鏈接的 「目標」 框裏:

Enter image description here


UPDATE

克里斯ñ把我的正確的方向。

我不得不做一些事情讓它工作,所以我會在這裏把它們:

Create and register the following registry file(* .reg的),這樣的PowerShell會知道TFS PowerShell的DLL文件:

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" 

在記事本中,創建一個新的文件,使用下面的命令:

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

IF statement prevents an error,如果我從Windows菜單中的鏈接加載。

然後,保存該文件作爲本:

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

這將使所有的貝殼和Windows上的所有配置文件運行的命令;如果你需要更小的範圍,請閱讀克里斯答案中的鏈接。

回答

2

閱讀關於PowerShell配置文件的文章Windows PowerShell Profiles。根據您設置的配置文件,您可以影響在該機器上啓動PowerShell的任何實例。

它應該從下面的腳本加載卡中(可以影響到所有用戶和所有炮彈):

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

感謝克里斯。我從中得到了我所需要的東西。我遇到的唯一問題是,當我從資源管理器菜單中鍵入「PowerShell」時,「適用於所有用戶和所有shell」的示例不起作用。它可以在此文件夾中使用此文件:D:\ Users \ Ray \ Documents \ WindowsPowerShell \ Microsoft.PowerShell_profile.ps1有任何想法嗎? – ray 2012-07-30 15:15:22

+0

如果您轉到我在答案中提到的配置文件,並添加以下行: Write-Host Hello從默認配置文件! ,當你打開shell時會顯示出來嗎? – 2012-07-30 15:17:56

+0

它沒有。我試着用「配置文件」。ps1「,然後將它重命名爲」Microsoft.PowerShell_profile.ps1「(我的個人資料中的同一個工作,這也不起作用,我完全可能錯過了某些東西,但它看起來像我做對了。 。 – ray 2012-07-30 15:25:09

相關問題