none
How To Add variable to scheduled task argument RRS feed

  • Question

  • Hi Guys,

    I currently patch my servers using powershell. This works fine however I have been asked to refine it a little. Current situation as an example for two file servers is:-

    2 text files with different servernames in

    2 PS files which each point to a different text file above

    Scheduled task to run at 23:59 on 3rd and 4th Tuesday of the month and call off the correct script for that week

    What I am trying to achieve to make any modifications to scripts less time consuming going forwards

    2 text files with different servernames in

    1 PS file that  the scheduled task will run at 23:59 on 3rd and 4th Tuesday of the month and call off the text file for that week

    basically make the below into the right syntax (if it is even possible)

    powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -command $servertopatch = get-content c:\scripts\serverlist1.txt -File "C:\scripts\serverpatching.ps1"

    Thanks

    Ricky

    Tuesday, October 22, 2019 9:45 AM

All replies

  • You cannot use both "command" and "file" at the same time.

    I recommend that you first use the help to see how the command line works

    powershell /?

    Next learn how to use and write a PowerShell script.  You can then modify the script to your needs.  What you are trying to do cannot be done as the code all needs to be in the PS script.

    powershell.exe -ExecutionPolicy Bypass -File C:\scripts\serverpatching.ps1 servername

    The server name will end up as an argument to PowerShell accessed as $args[0]


    \_(ツ)_/

    Tuesday, October 22, 2019 10:01 AM