How to have ConEmu execute a powershell script at startup

conemupowershell

I use the following command to launch new ConEmu powershell consoles.

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -new_console:n

I would like to pass an additional argument to specify a powershell script to run at startup of a new console. The following almost works but only prints the whole command and does not actually execute it:

ConEmu64.exe /config "shell" /dir "c:\" /cmd 'powershell -noexit -Command {Write-host "Hello world"}' -new_console:n

which produces:

Write-host Hello world
C:\>

while I am expecting:

Hello world
C:\>

Best Answer

Remove single quotas around your command. ConEmu executes intact string (command) which follows /cmd switch, with only exception - all -new_console... and -cur_console... are removed from this string before starting console.

ConEmu64.exe /config "shell" /dir "c:\" /cmd powershell -noexit -Command Write-host "Hello world" -new_console:n
Related Question