Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start CMD.exe from powershell with arguments in a script block?

Tags:

powershell

cmd

Is this possible?

I've just been trying something simple:

Start-Process -FilePath "C:\Windows\System32\cmd.exe" -verb runas -ArgumentList {echo hello1}

CMD starts in admin, but nothing happens after that.

The long story is, when I want to use "Remove-Item" I do not want to use the -Recurse argument because it will throw access denied errors for various reasons. The only way I know how to do it without any prompts is using rmdir inside a command prompt window.

Does anyone know a way to either suppress the prompt without -recurse or how I could start CMD and call rmdir with all its parameters?

like image 276
Fexception Avatar asked Oct 15 '18 21:10

Fexception


1 Answers

You pretty much have the whole thing. Just add a /c or /k at the beginning of your argument list.

/c - close command prompt after i run my command
/k - keep command prompt open

Start-Process -FilePath "C:\Windows\System32\cmd.exe" -verb runas -ArgumentList {/c echo hello1}
like image 116
Paul G Avatar answered Oct 10 '22 22:10

Paul G