Task Scheduler, Execute powershell script with a command

Welcome Forums General PowerShell Q&A Task Scheduler, Execute powershell script with a command

Viewing 3 reply threads
  • Author
    Posts
    • #237175
      Participant
      Topics: 1
      Replies: 1
      Points: 18
      Rank: Member

      I have a powershell api script that changing wifi passwords in Meraki.
      Now i want to add this script to Task Scheduler and execute it with a specific command line, for example:

      In “Action” section i’m always putting those lines:

      Program/script : Powershell.exe
      Add arguments : -ExecutionPolicy Bypass C:\Policies\Meraki\ChangePass.ps1

      But this won’t work here, because this script can be executed only when using this command:

      .\ChangePass.ps1 -site "Building1" -ssid "Wifi-Guest" -action "Change"

      Thanks for help

      • This topic was modified 3 weeks, 4 days ago by kobeat50.
      • This topic was modified 3 weeks, 4 days ago by kobeat50.
    • #237187
      Participant
      Topics: 5
      Replies: 2384
      Points: 6,066
      Helping Hand
      Rank: Community MVP

      al, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      To circumvent such problems I’d recommend using config or settings files instead of command line parameters. Then you even do not need to change the scheduled task if you want to change the behaviour of the script. 😉

    • #237193
      Participant
      Topics: 1
      Replies: 1
      Points: 18
      Rank: Member

      Hi Olaf,

      Thanks, i edited the post.

      And i didn’t understand the solution that you provided, can you explain a little bit more about it?

      Thanks

    • #237196
      Participant
      Topics: 5
      Replies: 2384
      Points: 6,066
      Helping Hand
      Rank: Community MVP

      Instead of providing command line parameters to control the behaviour of a script you save the needed setting in a text file next to the script file and in your script you read this settings file to get the contained settings. To make it easy to handle and easy to set up you should use a standardized format like JSON or a powershell data file. I like to use the latter one because it’s easy to write and easy to use.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.