Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have simple powershell script which gets the offset of a Ubuntu server with the time of the NTP server.

The command I run is

$result = ssh -i C:\temp\privatekey domain\username@servername "ntpdate -q"

When I run this script manually the $result variable is populated as expected. When I run as a scheduled task (as the same user) the script does not set the $result variable at all leaving it blank.

Is there further options I need to enter as part of the SSH command or as part of the scheduled task calling the ps script? Any help very much appreciated.

share|improve this question
I have just used a try catch to check what is happening and I am getting an error saying that "ssh is not recognized as the name of a cmdlet" – user166435 Mar 26 '13 at 11:57
Have you tried specifying full path of ssh? – infiniteRefactor Mar 26 '13 at 13:37

When you run a command from the command line, your entire environment, including your $PATH variable, is available to the command. When it's run from a scheduler, e.g. cron, that's not the case.

So when you write scripts that will be run from any type of schedulare, you should make sure to always include the full path to all commands in the script, or else to start by giving the script a proper $PATH setting.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.