如何使用管理单元从Windows资源管理器启动PowerShell
问题描述:
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控制台链接的 “目标” 框里:
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上的所有配置文件运行的命令;如果你需要更小的范围,请阅读克里斯答案中的链接。
答
阅读关于PowerShell配置文件的文章Windows PowerShell Profiles。根据您设置的配置文件,您可以影响在该机器上启动PowerShell的任何实例。
它应该从下面的脚本加载卡中(可以影响到所有用户和所有炮弹):
%windir%\system32\WindowsPowerShell\v1.0\profile.ps1
感谢克里斯。我从中得到了我所需要的东西。我遇到的唯一问题是,当我从资源管理器菜单中键入“PowerShell”时,“适用于所有用户和所有shell”的示例不起作用。它可以在此文件夹中使用此文件:D:\ Users \ Ray \ Documents \ WindowsPowerShell \ Microsoft.PowerShell_profile.ps1有任何想法吗? – ray 2012-07-30 15:15:22
如果您转到我在答案中提到的配置文件,并添加以下行: Write-Host Hello从默认配置文件! ,当你打开shell时会显示出来吗? – 2012-07-30 15:17:56
它没有。我试着用“配置文件”。ps1“,然后将它重命名为”Microsoft.PowerShell_profile.ps1“(我的个人资料中的同一个工作,这也不起作用,我完全可能错过了某些东西,但它看起来像我做对了。 。 – ray 2012-07-30 15:25:09