Reputation: 3512
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.
Upvotes: 6
Views: 4736
Reputation: 41
You can invoke powershell so that it starts itself with the script
Powershell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy RemoteSigned -noexit -File ""Full_Path_of_MyScript.ps1""'}"
Upvotes: 1
Reputation: 943
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
Upvotes: 6
Reputation: 354376
That's a property of the shell link in the Start Menu which starts PowerShell, so you'd have to go through that:
start "" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" ...
It's not pretty, it depends a little on where that resides (and might break on foreign language versions).
Upvotes: 3