PowerShell window when launched from a batch file

I have a batch file that runs a PowerShell script.

Batch file:

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

MyScript.ps1:

 Write-Output "Hello World!" 

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

Thanks.

+6
source share
3 answers

If you really need a blue background, add code in your script 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 
+6
source

This is the property of the shell link in the Start menu that launches PowerShell, so you have to go through this:

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

It's not very much, it depends a little on where it is (and can break foreign language versions).

+3
source

You can call powershell to start with a script

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

Source: https://habr.com/ru/post/908653/


All Articles