1

I have a powershell script on my Windows server which does some active directory operations. I wish to call that script from another Linux machine using a shell script.

I have installed powershell server on my Windows server and can communicate with my linux machine using key based ssh authentication.

Since Windows does not support SSH connections on its own, I have installed a software called Powershell server (http://www.powershellserver.com/) on my Windows server.

The issue is that my script just stops once the command for ssh to Windows server is executed.

My shell script below:

#!/bin/bash
echo "script run"
GROUP=$1
ACCOUNT=$2
ssh Administrator@<Windowshostname>
sleep 10
echo "<pathtoscript>\scriptname.ps1 -group $GROUP -account $ACCOUNT"
sleep 5
echo "exit"
exit

I have tried without the echo command as well and it still hangs. Any idea what I must be doing wrong here? How can I make it work please?

1
  • I think you just need ssh Administrator@Winhost "sleep 10; /path/to/script -group $GROUP -account $ACCOUNT" Commented Mar 8, 2016 at 11:23

2 Answers 2

0

You cannot ssh into a Windows box unless you install a SSH daemon. You have two options:

1- You need to connect via Remote PowerShell (WINRM).

2- Install SSH daemon and connect via SSH (Check here)

3- You can also use PowerShell Web Access (Windows Servers.)

UPDATE: If you are using PowerShellServer.com then there are some things you can do to try to understand more.

  • Test scriptname.ps1 locally in Windows Server

  • Edit your scriptname.ps1 in the first line to create a file somewhere and after execution check if that file exists. This way you will know if script is being executed or not.

  • Execute Get-ExecutionPolicy and check you can run scripts. Remove constraints by temporary Set-ExecutionPolicy unrestricted

Sign up to request clarification or add additional context in comments.

5 Comments

I can connect to the Windows box using the ssh command as I have installed powershell server on my Windows VM. ssh Administrator@<Windowshostname> PowerShell Server: SSH-Enabled PowerShell Access for Windows (powershellserver.com) PS C:\ProgramData>
But Windows by default doesn't allow SSH. What have you installed to vanilla Windows?
You should edit your question and add that information as it is relevant.
Just did. I cannot use power shell web access as it has to be through a Unix shell script only. I have to use that script in another implementation.
Yep. I can execute my script locally. I am doing some Active directory operations and that works well on local execution of the script.
0

Tried the operation using an "expect" script and it all works well now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.