Skip to content

Instantly share code, notes, and snippets.

@speguero
Last active August 23, 2023 21:16
Show Gist options
  • Save speguero/049b7ebf4be1d7f1f8578a466e92ba94 to your computer and use it in GitHub Desktop.
Save speguero/049b7ebf4be1d7f1f8578a466e92ba94 to your computer and use it in GitHub Desktop.
:: Allows admins to execute batch scripts on
:: remote Windows hosts.
@echo off
set CMD=%1
set SYS=%2
set VERBOSITY=%3
set CMD=%CMD:"=%
set SYS=%SYS:"=%
set TASK_NAME=quickdeploy
set TASK_CMD=cmd.exe /c '%CMD%'
:: MAIN
echo.
echo Running script on "%SYS%"...
echo.
if "%VERBOSITY%" == "-v" (
echo Command: %CMD%
echo.
)
ping -n 1 "%SYS%" 1>nul || (
echo ERROR: Could not receive ICMP ping response from "%SYS%".
goto END
)
schtasks ^
/create ^
/tn "%TASK_NAME%" ^
/tr "%TASK_CMD%" ^
/s "%SYS%" ^
/ru "NT AUTHORITY\SYSTEM" ^
/sc once ^
/rl highest ^
/st 00:00 ^
/f
schtasks /run /tn "%TASK_NAME%" /s "%SYS" && ^
schtasks /delete /tn "%TASK_NAME%" /s "%SYS%" /f >nul 2>&1
:END
:: --------
:: SYNOPSIS
:: --------
::
:: quickdeploy.cmd script host [-v]
::
:: Example: quickdeploy.cmd \\server\share\script.cmd abc123 -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment