Create schedule task on mulitple servers

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

  • Author
    Posts
  • #76325

    Jaapie bakker
    Participant

    Hi Guys,

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

    $servers = Import-csv "C:\temp\servers.csv"
    ForEach ($server in $servers){
    #createfolder
    New-Item "\\$($Server.Servername)\c$\Test1" -type directory
    Start-Sleep 1
    #copyfile
    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
    Participant

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

    https://technet.microsoft.com/en-us/library/cc725745.aspx

  • #76330

    Simon B
    Participant

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

    https://serverfault.com/questions/586655/scheduling-tasksjobs-across-servers-from-central-location-windows-server

  • #76346

    Kevyn
    Participant

    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
    Participant

    Thanks Kevyn, i will look into Invoke-Command

You must be logged in to reply to this topic.