1

I need create schedule task programmatically using Powershell (PS remoting).

My task executes a powershell script (and other cases a script cmd) immediately.

$powershellcmd = (get-command powershell.exe).Definition
$upgradeWSPps1 = (Join-Path $ScriptDirectory Tests.LifeCycle.Deploy.MOSS.UpgradeWSP.ps1)

$cmdToRun = "$powershellcmd -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -File ""$upgradeWSPps1"" "

If you're creating a scheduled task by providing $cmdToRun to schtasks then you'll need to use both Windows CLI style escape character and Powershell style escape characters for double-quotes. In Powershell the back-tick ` is the escape character, but in Windows CLI (classic Windows shell) it is the forward slash.

Any suggestions about it ? any good sample code ?

0

Why would you want to create a scheduled task on a remote computer to immediately run a script? Just run the script directly on the remote computer.

Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND }
  • I need it, another issues in my company (permissions in deploy sharepoint, etc). I want testing create scheduled task, I need do it that way. – Kiquenet Sep 10 '12 at 10:55
  • The command to create scheduled tasks is schtasks. – Ansgar Wiechers Sep 10 '12 at 12:21
  • If you're creating a scheduled task by providing $cmdToRun to schtasks then you'll need to use both Windows CLI style escape character and Powershell style escape characters for double-quotes. In Powershell the back-tick ` is the escape character, but in Windows CLI (classic Windows shell) it is the forward slash. Any good sample about it? – Kiquenet Sep 11 '12 at 6:26
  • The escape character for CMD is the caret ^ (and sometimes the backslash), not the forward slash. – Ansgar Wiechers Sep 11 '12 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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