Skip to content

Close cmd psexec after exec

ps1
$psexec = "<PSEXECROOT>\PsExec.exe"
$args= "-u <domain>\<user> -p <password> `"<path>\<to>\<exec>`" /accepteula"

Stop-Process -Name "<execname>" -Force
start-process $psexec -ArgumentList $args -NoNewWindow | out-null

# wait 2 secondes
Start-Sleep 2

Stop-Process -Name "psexec" -Force
Stop-Process -Name "powershell" -Force
exit