Dan*_*eny 33 shell powershell powershell-3.0
当您从其中一个预安装的快捷方式启动PowerShell窗口时,我会依赖它的漂亮蓝色.但是,如果你手动启动powershell.exe,你没有得到这些颜色,你得到黑/白:(
这是因为默认设置是在快捷方式(.lnk)文件上设置的:

我在Explorer上下文菜单中有一个"PowerShell Prompt Here"条目,我希望它使用与通常的快捷方式相同的漂亮颜色来启动PowerShell; 黑色很糟糕,而且有不同颜色的窗户会让人感到困惑(特别是当我有一些经常打开的老式指令窗户也是黑色的时候!).
到目前为止,我发现了两个问题:
有没有办法从命令行启动PowerShell(即我可以将其作为资源管理器上下文菜单项嵌入到注册表中),它将使用与快捷方式相同的设置?
x0n*_*x0n 31
编辑您的个人资料脚本(由$ profile指向)并自己设置所需的颜色:
# set regular console colors
[console]::backgroundcolor = "darkmagenta"
[console]::foregroundcolor = "darkyellow"
# set special colors
$p = $host.privatedata
$p.ErrorForegroundColor = "Red"
$p.ErrorBackgroundColor = "Black"
$p.WarningForegroundColor = "Yellow"
$p.WarningBackgroundColor = "Black"
$p.DebugForegroundColor = "Yellow"
$p.DebugBackgroundColor = "Black"
$p.VerboseForegroundColor = "Yellow"
$p.VerboseBackgroundColor = "Black"
$p.ProgressForegroundColor = "Yellow"
$p.ProgressBackgroundColor = "DarkCyan"
# clear screen
clear-host
Run Code Online (Sandbox Code Playgroud)
Rex*_*din 22
这是一个非常简单的方法:
开始 - >运行"sysdm.cpl" - >高级 - >环境变量
向下滚动系统变量,双击PATHEXT
添加.LNK; 如下图所示:

Copy-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" "C:\Windows\System32\powershell.lnk"
Run Code Online (Sandbox Code Playgroud)
您可以根据自己的喜好在C:\ Windows\System32中进一步自定义.lnk.
请注意,这只会起作用,因为您已将.lnk添加到可接受的扩展名列表中,并且c:\ windows\system32是搜索路径中的第一项(PATH系统变量).
如果通过cmd.exe启动,则不会自定义控制台.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\PowerShellHere\command]
@="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\""
[HKEY_CLASSES_ROOT\Directory\shell\PowerShellHere\command]
@="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\""
Run Code Online (Sandbox Code Playgroud)
我使用cmd.exe调用"start",它将启动powershell.lnk并将当前工作目录作为参数传递.似乎没有从地址栏工作.我应该在45分钟前回家,但你的问题很有趣!:)
加分点:您可以将发送到Powershell的命令进行线程化.因此,如果您要修改Powershell控制台的title属性:
\"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'"
Run Code Online (Sandbox Code Playgroud)
只需在命令之间添加分号即可.
快乐的炮击
Art*_*yom 11
我发现使用concfg工具和scoop为Powershell安装颜色和字体非常有用:
安装独家新闻:
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
Run Code Online (Sandbox Code Playgroud)安装concfg:
scoop install concfg
Run Code Online (Sandbox Code Playgroud)安装Solarized主题:
concfg import solarized
Run Code Online (Sandbox Code Playgroud)就是这样,感谢作者!
单击系统菜单(窗口左上角的PowerShell图标),然后单击"默认值".您可以在此处更改默认颜色,PowerShell Prompt Here命令将遵循该颜色.
来自:https://superuser.com/a/523017/109736
小智 6
执行此操作的正确方法是使用注册表
cd hkcu:/console
$0 = '%systemroot%_system32_windowspowershell_v1.0_powershell.exe'
ni $0 -f
sp $0 ColorTable00 0x00562401
sp $0 ColorTable07 0x00f0edee
Run Code Online (Sandbox Code Playgroud)