gpt4 book ai didi

从批处理文件启动时的 PowerShell 窗口

转载 作者:行者123 更新时间:2023-12-03 19:42:06 25 4
gpt4 key购买 nike

我有一个启动 PowerShell 脚本的批处理文件。

批处理文件:

START Powershell -executionpolicy RemoteSigned -noexit -file "MyScript.ps1"

MyScript.ps1 :
Write-Output "Hello World!"

它工作正常,只有一个异常(exception)。窗口的外观类似于旧的 cmd.exe(黑色背景)而不是 PowerShell(蓝色背景)。
如果我从批处理文件启动它,如何获得真正的 PowerShell 窗口?

谢谢。

最佳答案

如果您真的想要蓝色背景,请在脚本中添加代码以更改背景颜色。

#save the original
$original=$host.ui.RawUI.BackgroundColor
$front=$host.ui.RawUI.ForegroundColor
$host.ui.RawUI.BackgroundColor="DarkBlue"
$host.ui.RawUI.ForegroundColor="White"
cls
#run your code
dir c:\scripts

#set it back
$host.ui.RawUI.BackgroundColor=$original
$host.ui.RawUI.ForegroundColor=$front

关于从批处理文件启动时的 PowerShell 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9317235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com