我该如何删除PowerShell的启动文本?

64

PowerShell 从版本 6 开始具有类 Unix 风格的 /etc/issue,其中提到了指向文档的链接。

PowerShell v6.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

这很好,但是:

  • 我知道文档在哪里
  • 我知道我启动了 PowerShell 6

我该如何删除部分或全部消息?如果我没记错,PowerShell 5 仍然有版权信息的提示,所以可能无法删除它,但是删除最后三行仍会有所帮助。


1
我这里没有 PS Core,但你尝试过在命令行选项中传递“-nologo”吗?这是适用于 Windows Powershell(5.0)和通常适用于 MS 软件的相关选项。 - Christian.K
@Christian.K 恰好是我想要的!将其添加为答案,我会标记为正确。 - mikemaccana
6
微软决定在启动横幅中宣传每个新的小版本更新后,这个问题变得更加相关。 - Niko Pasanen
14个回答

76

使用-NoLogo选项。

-NoLogo启动 PowerShell 控制台时不会显示版权横幅。

pwsh.exe -nologo ...other arguments...

12
小提示:如果你正在使用新的Windows终端(强烈推荐),那么你可以编辑它的设置,使其启动powershell.exe -nologo,这样会非常好用。 - Orion Edwards

47

如果您正在使用新的Windows终端,则:

  1. 前往设置:

    Windows Terminal Settings

  2. 在PowerShell命令行中添加参数-nologo

    Powershell Command Line


16
作为给 VS Code 用户的额外提示,您可以通过在 settings.json 中设置 "terminal.integrated.shellArgs.windows": "-nologo", 来向集成终端添加 -nologo 参数。 - Niko Pasanen
3
同意使用 VS Code,尽管我建议将它设为 ["-NoLogo"],因为从技术上讲该字段应该是一个数组。 - FSCKur
你可能需要自己添加“commandLine”选项。在我的设置中,它并不存在。 - Huseyin Yagli

17

从 @sandu 的回答中,可以进行以下改进。

"terminal.integrated.profiles.windows": {
   "PowerShell": {
       "source": "PowerShell",
       "args": ["-noLogo"]
   }
},
"terminal.integrated.defaultProfile.windows": "PowerShell",

13

现在你可以在Windows终端设置中添加-nologo

enter image description here


你如何进入Windows终端设置? - Stevoisiak
@Stevoisiak 前往微软商店,搜索“Windows 终端”,然后安装它。 - Lucky Person
@Stevoisiak 点击标题栏区域的向下箭头。 - Andrew Morton

6
最简单的方法是在你的$profile文件顶部添加Clear-Host

1
点赞,因为这很有帮助,但我会等一下看看是否有文件或注册表条目可以编辑以实际删除文本,而不仅仅是清除它。 - mikemaccana
6
当从其他shell调用PowerShell时,这可能会导致不希望出现的行为。 - idanp

4
你可以打开 PowerShell 并输入 $profile 命令,你会得到 Microsoft.PowerShell_profile.ps1 文件的路径。用记事本打开这个文件(没有则创建一个),然后输入 clear 或者 cls 命令。保存并退出。这个文件中的命令将在你打开 PowerShell 时执行。

enter image description here


1
这意味着在终端之间随机切换会清除你的屏幕,这并不理想。 - Sv443

3
我正在通过以下方式解决顶部的问题:

enter image description here


3
我的做法是进入文件 > 首选项 > 设置,然后在搜索栏中输入terminal.integrated.defaultProfile.windows如果需要可以更改windows为其他支持的操作系统)。现在应该只有一个选项可供选择(这就是我包含windows的原因)。点击下面的在settings.json中编辑链接。它现在应该打开settings.json并生成所需的行以修改默认终端配置文件,类似于:
"terminal.integrated.defaultProfile.windows": "",

在那条线以上,你可以创建自己的个人资料:

"terminal.integrated.profiles.windows": {
    "PowerShell -nologo": {
      "source": "PowerShell",
      "args": ["-nologo"]
    }
},

可以自己命名配置文件并添加所需参数。完成后,将配置文件名称设置为之前为您生成的选项。在本示例中,应如下所示:

"terminal.integrated.defaultProfile.windows": "PowerShell -nologo",

保存并关闭。现在,当您打开终端时,例如没有任何标志。


1
其他答案已经过时。 @sandu的答案可以通过在配置文件名中删除-nologo来改进,因为"terminal.integrated.defaultProfile.windows"只接受有效值:"PowerShell""Command Prompt""Git Bash""kali-linux (WSL)""Legacy (WSL)"。 因此,答案可以像我的答案下面一样被覆盖。 - Konjesh Esbrading

3

np8这个回答中所说,隐藏Visual Studio Code集成终端中的初始文本的方法如下:


  1. Open the workspace settings file (./.vscode/settings.json) or the user settings file (search for Preferences: Open Settings (JSON) in the command palette, opened with F1)

  2. Add the following inside the outer-most "layer" of curly brackets:

    "terminal.integrated.shellArgs.windows": [
        "-nologo"
    ]
    

一个很不错的答案,已经被点赞了,但是我删除了与其他 shell 相关的文本,因为这是一个 PowerShell 的问题。 - mikemaccana

2

中文版用户也可以在Windows终端设置中添加-nologo:

如下图所示:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接