Skip to main content
added 213 characters in body
Source Link
Will
  • 45
  • 6

For all intents and purposes, I am a novice with PS.

The command I'd like to run (it works when run manually) is:

(I realize parts are probably redundant)

Start-Process -WindowStyle hidden "$psHome\powershell.exe" -verb runas -ArgumentList "-file c:\distributedfiles\source.ps1 -ErrorAction SilentlyContinue"

I want this ^ command to execute from a Scheduled Task which needs to be created via powershell.

I've tried such things as:

schtasks.exe /create /tn backuptest /tr "c:\distributedfiles" "powershell.exe `-executionpolicy unrestricted -file c:\distributedfiles\source.ps1 -verb runas -erroraction silentlycontinue`" /d mon /sc once /st 12:33 /rl highest /f /z

To no success. I know I am wayyy off the mark with my syntax. Help would be appreciated!

edit: in this case would it be easier to just have 2 .ps1 files one with my Start-Process command, it would be invoked by scheduled task - then invoke my main source script? I sorta imagine that being easiest.

For all intents and purposes, I am a novice with PS.

The command I'd like to run (it works when run manually) is:

(I realize parts are probably redundant)

Start-Process -WindowStyle hidden "$psHome\powershell.exe" -verb runas -ArgumentList "-file c:\distributedfiles\source.ps1 -ErrorAction SilentlyContinue"

I want this ^ command to execute from a Scheduled Task which needs to be created via powershell.

I've tried such things as:

schtasks.exe /create /tn backuptest /tr "c:\distributedfiles" "powershell.exe `-executionpolicy unrestricted -file c:\distributedfiles\source.ps1 -verb runas -erroraction silentlycontinue`" /d mon /sc once /st 12:33 /rl highest /f /z

To no success. I know I am wayyy off the mark with my syntax. Help would be appreciated!

For all intents and purposes, I am a novice with PS.

The command I'd like to run (it works when run manually) is:

(I realize parts are probably redundant)

Start-Process -WindowStyle hidden "$psHome\powershell.exe" -verb runas -ArgumentList "-file c:\distributedfiles\source.ps1 -ErrorAction SilentlyContinue"

I want this ^ command to execute from a Scheduled Task which needs to be created via powershell.

I've tried such things as:

schtasks.exe /create /tn backuptest /tr "c:\distributedfiles" "powershell.exe `-executionpolicy unrestricted -file c:\distributedfiles\source.ps1 -verb runas -erroraction silentlycontinue`" /d mon /sc once /st 12:33 /rl highest /f /z

To no success. I know I am wayyy off the mark with my syntax. Help would be appreciated!

edit: in this case would it be easier to just have 2 .ps1 files one with my Start-Process command, it would be invoked by scheduled task - then invoke my main source script? I sorta imagine that being easiest.

Source Link
Will
  • 45
  • 6

How do I write this powershell 2.0 command, which creates a scheduled task, to run another powershell command?

For all intents and purposes, I am a novice with PS.

The command I'd like to run (it works when run manually) is:

(I realize parts are probably redundant)

Start-Process -WindowStyle hidden "$psHome\powershell.exe" -verb runas -ArgumentList "-file c:\distributedfiles\source.ps1 -ErrorAction SilentlyContinue"

I want this ^ command to execute from a Scheduled Task which needs to be created via powershell.

I've tried such things as:

schtasks.exe /create /tn backuptest /tr "c:\distributedfiles" "powershell.exe `-executionpolicy unrestricted -file c:\distributedfiles\source.ps1 -verb runas -erroraction silentlycontinue`" /d mon /sc once /st 12:33 /rl highest /f /z

To no success. I know I am wayyy off the mark with my syntax. Help would be appreciated!