So, I'm trying to create a scheduled task on a large number of servers (60+) that will run a PowerShell script. I have the schtask command figured out and tested, and if I run it against a single server, it runs just fine.
So, since I need to do it against 60+ servers, I created a .txt file containing all of the site codes. Then I have a variable created, defined as that text file. Then the foreach-object loop is created, starting with defining a variable adding the site code to the rest of the server name, then running the schtasks command against that variable. And that I'm guessing is where it's failing (it's just saying "Supply values for the following parameters", so it's not super helpful.
Does anyone have any idea as to where I'm going wrong? I'm not the strongest scripter, so any help would be super appreciated. Here's the full script:
$Site = Get-Content -Path D:\folder1\Sites.txt | ForEach-Object { $server = $site + "-file-p50" .\schtasks /Create /S $Server /RU "SYSTEM" /RP /SC ONCE /TN "DFS Mapping" /TR "powershell.exe C:\users\<username>\desktop\datapaths.ps1" /ST "4:00" /SD "06/06/2017" /F /RL HIGHEST }