有没有办法可以更改 PowerShell 横幅消息?

有没有办法可以更改 PowerShell 横幅消息?

每次启动 PowerShell(除非使用参数-nologo)时,都会出现 Microsoft 版权声明消息。

Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

有没有办法修改此横幅以添加更多有趣和/或有用的信息(例如:PowerShell 版本、当前系统日期/时间、“您好,Falken 教授。我们可以玩游戏吗?”等)?

答案1

我认为你不能修改上面的文本,但你也可以让它自动打印你自己的文本,你只需要编辑你的 powershell 快捷方式以始终启动-nologo

你可以通过编辑你的PowerShell 配置文件

要查找您的配置文件,您只需键入$profile并按回车键,它就会显示配置文件脚本的完整路径。配置文件可能存在也可能不存在,但它将返回 power shell 首先尝试查找的路径。

该命令Test-Path $profile将告诉您该配置文件是否存在。

在正确的位置创建配置文件脚本后,每次启动 power shell 时,它都会运行脚本中的所有内容。因此,要获得所需的内容,您需要使用以下内容创建配置文件

Write-Host 'Powershell' $PsVersionTable.PSVersion '-' (Get-date)
Write-Host 'Greetings Professor Falken. Shall we play a game?'
Write-Host ''

但是,如果你这样做,你可能会遇到麻烦,你可能会得到类似以下的错误

File C:\Users\Scott\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 cannot be loaded because the execution
of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:2
+ . <<<<  'C:\Users\Tami\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

如果你得到类似的错误,请阅读帮助文件,输入以下内容get-help about_signing,你可以将其设置为打开未签名的脚本1,或者将设置更改为仅允许签名的脚本和完成后自行签署脚本

一旦让它正常工作,每次启动 powershell 时-nologo它都会看起来像

Powershell 2.0 - 9/15/2013 2:41:42 PM
Greetings Professor Falken. Shall we play a game?

PS C:\Users\Scott> 

1:我将我的机器设置为RemoteSigned仅当脚本设置了“来自另一台计算机”标志时才需要签名。

相关内容