techthoughts2
1/30/2017 - 7:43 PM

Running commands in CMD from powershell

Running commands in CMD from powershell

$command = 'C:\somepath\someexe.exe somearg'
iex $command

#full working example
$command = 'cmd.exe /c "C:\Program Files (x86)\Bginfo\BgInfo.exe" "C:\Program Files (x86)\Bginfo\config_2016.bgi\" /silent /accepteula /timer:0'
iex "& $command"

#issue the command
cmd.exe /c dir /w

#leaves the argument untouched
cmd.exe --% /c dir %WINDIR% /w