Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell window when started from a batch file

I have a batch file that starts a PowerShell script.

Batch file:

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

MyScript.ps1 :

Write-Output "Hello World!"

It works fine, with one exception. The appearance of the window is like the old cmd.exe (black background) and not the PowerShell (blue background).
How can I get the true PowerShell window, if I start it from a batch file?

Thanks.

like image 774
mcu Avatar asked Feb 16 '12 18:02

mcu


1 Answers

If you really want a blue background, in your script add code to change the background color.

#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
like image 162
Jeffery Hicks Avatar answered Nov 13 '22 00:11

Jeffery Hicks