Create schedule task on mulitple servers

This topic contains 4 replies, has 3 voices, and was last updated by  Jaapie bakker 10 months, 2 weeks ago.

  • Author
  • #76325

    Jaapie bakker

    Hi Guys,

    I've created the following script for like ~250 server

    $servers = Import-csv "C:\temp\servers.csv"
    ForEach ($server in $servers){
    New-Item "\\$($Server.Servername)\c$\Test1" -type directory
    Start-Sleep 1
    Copy-Item D:\Scripting\Files\bla1.txt -Destination \\$($Server.Servername)\c$\Test1

    This works. Now i would like to create a scedule task on the servers remotly.

    When i do it directly to one server i use:

    $Action = New-ScheduledTaskAction -Execute "Cmd"
    $Trigger = New-ScheduledTaskTrigger -Once -At 17:00
    Register-ScheduledTask Bodhi -Action $Action -Trigger $Trigger

    This works. But i would like to do it on all the servers but with foreach i cannot fix it.

    Some help please 🙂

  • #76328

    Simon B

    why not use group policy and push the task that way ?

  • #76330

    Simon B

    or if you wanted to do it via Powershell have a look at the bottom answer here using SCHTASKS.EXE

  • #76346


    You might put your scheduled task commands into a script file, and then use the Invoke-Command cmdlet to run that script on each remote server. See the help for the Invoke-Command cmdlet for details.

  • #76402

    Jaapie bakker

    Thanks Kevyn, i will look into Invoke-Command

You must be logged in to reply to this topic.