Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created August 2, 2011 20:21
Show Gist options
  • Save thinkerbot/1121114 to your computer and use it in GitHub Desktop.
Save thinkerbot/1121114 to your computer and use it in GitHub Desktop.
Execute a powershell script via ssh
# Notes:
# 1) The input format must be specified to prevent ssh from hanging
# 2) The full path to the script is required
# 3) An SSH server must be running on the Windows box, naturally. WinSSHD
# is free for personal, non-commercial use and worked for this example.
# See http://www.bitvise.com/winsshd
#
# You have to set the execution policy for scripts so that powershell has
# permissions to run the script. To do so, search for 'Powershell' under
# the Start menu. Then right-click and 'Run as administrator' so that you
# have permissions to set permissions. Then:
#
# PS> Set-ExecutionPolicy RemoteSigned
#
# As a result you can run scripts you write but not unsigned ones from
# remote sources. See http://technet.microsoft.com/en-us/library/ee176949.aspx
#
# To execute via ssh:
#
# $ ssh user@host '"C:\path\to\run.bat"'
#
# Note the inner quotes are superfluous here but required if the path has
# a space in it.
powershell -InputFormat None -F "C:\script.ps1"
# As per the bat file, put this at "C:\script.ps1"
echo "hello world"
@gdw2
Copy link

gdw2 commented Apr 14, 2014

Thanks. Winsshd was hanging for me when I tried to run powershell without the "-InputFormat None"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment