-
-
Save phuysmans/24ae885a836054a0cc892f48432b326e to your computer and use it in GitHub Desktop.
Execute a powershell script via ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As per the bat file, put this at "C:\script.ps1" | |
echo "hello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment