繁体   English   中英

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

[英]PowerShell window when started from a batch file

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

批处理文件:

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

MyScript.ps1:

Write-Output "Hello World!"

它工作正常,但有一个例外。 窗口的外观类似于旧的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的shell链接的属性,因此您必须完成以下操作:

start "" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" ...

它不漂亮,它取决于它所在的位置(可能会破坏外语版本)。

您可以调用powershell,以便它可以通过脚本启动

Powershell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -noexit -File ""Full_Path_of_MyScript.ps1""'}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM