Create a scheduled task on a remote computer (Windows 2008)

Hi, I have been struggling with a PS script where I am trying to execute a batch job on a remote computer. The batch job resides on a network share, so I will be using a UNC path.
In the script, the user name, password, and computer name are queried.
Besides trying various scheduled tasks, etc, I am now to the point of using invoke-command (I seem to remember Don says never to use that :slight_smile: ) …

Here is my command:

Invoke-Command -ComputerName name -ScriptBlock { Start-Process “\path\pleasehelpimgoingcrazy.cms” -verb runAs }

I am getting an access denied error. I am using my account with the highest privileges. Can someone help?


This is the “second hop” problem of PowerShell remoting. If you search for that term you’ll find tons of results, but the short answer is that you need to use either Kerberos delegation (in an AD environment where this is possible) or CredSSP.

Thanks Dave. Would it be easier to use a scheduled task then? I have had my issues with that as well, using an XML file for the task.
If you were to use a scheduled task, which method would you use to set it up? Besides using schtasks.exe (always some issue with that :frowning: ) … and I have tried New-Object -ComObject(“Schedule.Service”) … but I seem to always have issues with permissions also.
Which poison would you pick? :slight_smile:

On 2008, I always used schtasks.exe.

For using credssp, you can check my post here how to do it trough a GPO. Not the safest thing, but it works nevertheless. :slight_smile:

Thanks Dave and Richard :slight_smile: