windows - How can I launch .cmd files on a remote machine? -
i need able launch .cmd file on remote machine, from within directory file resides on machine.
i've tried: invoke-command -computername test123 -scriptblock { cmd /c c:/myfile.cmd }
in powershell, launches .cmd, fails because can't find corresponding .cmds 1 launches (which reside in same directory).
is there way launch .cmd file, , have it's execution persist? i.e., after powershell window closed, .cmd continue run on remote machine.
you need change working directory in scriptblock. add set-location
before calling batch script:
invoke-command -computername test123 -scriptblock { set-location 'c:\' & cmd /c ".\myfile.cmd" }
if need create detached process, can instance via wmi:
$hostname = 'test123' $command = 'c:\path\to\script.cmd' $workdir = 'c:\working\directory' $p = [wmiclass]"\\$hostname\root\cimv2:win32_process" $p.create($command, $workdir)
note need admin privileges on remote host this.
Comments
Post a Comment