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

mcu*_*mcu 6 powershell command-line batch-file

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

批处理文件:

START Powershell -executionpolicy RemoteSigned -noexit -file "MyScript.ps1"
Run Code Online (Sandbox Code Playgroud)

MyScript.ps1:

Write-Output "Hello World!"
Run Code Online (Sandbox Code Playgroud)

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

谢谢.

Jef*_*cks 6

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

#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
Run Code Online (Sandbox Code Playgroud)