【问题标题】:How to launch PowerShell from Windows Explorer with Snap-Ins如何使用管理单元从 Windows 资源管理器启动 PowerShell
【发布时间】:2012-07-30 14:24:45
【问题描述】:

This question 回答如何从 Windows 资源管理器启动 PowerShell。

我想从 Windows 资源管理器启动 PowerShell,并预加载了我的 TFS Shell 管理单元。

我用这个命令**创建了一个批处理文件(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 控制台链接的“目标”框:


更新

Chris N 让我朝着正确的方向前进。

我必须做一些事情才能让它发挥作用,所以我把它们放在这里:

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 上的所有 shell 和所有配置文件运行;如果您需要更小的范围,请阅读 Chris 答案中的链接。

【问题讨论】:

    标签: powershell registry windows-explorer tfs-power-tools


    【解决方案1】:

    阅读关于 PowerShell 配置文件的精彩文章 Windows PowerShell Profiles。根据您设置的配置文件,您可以影响该计算机上启动的任何 PowerShell 实例。

    应该可以从以下脚本加载管理单元(以影响所有用户和所有 shell):

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

    【讨论】:

    • 谢谢克里斯。我很好地得到了我需要的东西。我唯一的问题是,当我从资源管理器菜单中键入“PowerShell”时,“适用于所有用户和所有 shell”的示例不起作用。但是它在这个文件夹中使用这个文件:D:\Users\Ray\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 有什么想法吗?
    • 如果您转到我在答案中提到的配置文件,并添加以下行:默认配置文件中的 Write-Host Hello! ,打开shell时会出现吗?
    • 它没有。我在该目录中使用“profile.ps1”进行了尝试,然后将其重命名为“Microsoft.PowerShell_profile.ps1”(我的配置文件中的同一个有效但也不起作用。我完全可能在那里遗漏了一些东西,但它看起来我做得对。
    • 它适用于我的机器上的每个 shell。只是为了验证,您打开了 C:\Windows\System32\WindowsPowerShell\v1.0\ 并在那里创建了一个名为 profile.ps1 的新文件。如果你去记事本,选择文件,打开然后粘贴:%windir%\system32\WindowsPowerShell\v1.0\profile.ps1 它会打开你的脚本吗?
    • 好的...使用记事本手动创建它使其工作。我首先尝试让 PowerShell 创建它,然后尝试使用 Notepad++ 手动创建。它不起作用;也许今天早上没有开火。现在可以走了。非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    相关资源
    最近更新 更多