每次启动 PowerShell(除非使用-nologo参数),都会出现 Microsoft 版权通知消息。
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
Run Code Online (Sandbox Code Playgroud)
有没有办法修改此横幅以添加更多有趣和/或有用的信息(例如:PowerShell 版本、当前系统日期/时间、“您好 Falken 教授。我们玩游戏吗?”等)?
我不认为你可以修改上面的文本,但你也可以让它自动打印你自己的文本,你只需要编辑你的 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 ''
Run Code Online (Sandbox Code Playgroud)
但是,如果您这样做,您可能会遇到障碍,您可能会收到类似以下内容的错误
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
Run Code Online (Sandbox Code Playgroud)
如果您遇到这样的错误,请通过键入来阅读帮助文件,get-help about_signing以便您可以将其设置为打开未签名的脚本1或将设置更改为仅允许已签名的脚本并在您完成后自己对脚本进行签名。
每次使用-nologo它启动 powershell 时,一旦一切正常,它就会看起来像
Powershell 2.0 - 9/15/2013 2:41:42 PM
Greetings Professor Falken. Shall we play a game?
PS C:\Users\Scott>
Run Code Online (Sandbox Code Playgroud)
1:RemoteSigned如果脚本设置了“来自另一台计算机”标志,我将我的机器设置为只需要签名。
| 归档时间: |
|
| 查看次数: |
8078 次 |
| 最近记录: |