Bored002
Bored002

Reputation: 403

Powershell scriptopen a window and send command to window

I'm trying to open a CMD as system using PowerShell and then send a command to that system window. what i've got so far is this:

$opensystempromt = '"/c PsExec.exe -is cmd.exe'
[System.Diagnostics.Process]::Start('cmd.exe',$opensystempromt)
$systemcommand = 'CustomerService.exe deploy aa.txt bb.txt'

what i can't figure out is how to send the system command to the newly opened CMD. and there's no documentation for it anywhere, that i could find

Upvotes: 0

Views: 62

Answers (1)

SikorskyS60
SikorskyS60

Reputation: 180

I'd use Start-Process to open cmd.

Start-Process -FilePath "C:\Windows\System32\cmd.exe" -verb runas -ArgumentList {/k Insert your variables here}

with -verb runas you'll open cmd as an administrator. ArgumentList is your "command part". /k leaves the cmd open, after the commands are done. If you want cmd to close instead, use /c.

Upvotes: 1

Related Questions