Task Scheduler, Execute powershell script with a command

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

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. :wink:

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

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.