Scheduldtask script question

This topic contains 5 replies, has 3 voices, and was last updated by  Max Kozlov 9 months, 3 weeks ago.

  • Author
  • #76536

    Jaapie bakker

    Guys, you helped me so much this week. Last question to complete everything

    I've got on every server (+-150) my reboot schedule task. but every month i would like to restart the servers after patching.

    I created the following:

    $servers = Get-Content C:\temp\servers.txt
    $DateTime = Read-Host "Date and Time (MM/DD/YY)"
    $User = Read-host "Admin username"
    $Password = Read-Host "Enter Password" -AsSecureString

    foreach ($server in $servers)
    Enter-PSSession $server
    $Time = New-ScheduledTaskTrigger -At $DateTime -Once
    Set-ScheduledTask -TaskName "Rebootserver" -Trigger $Time -User nbdbiblion\$user -Password $password

    I works, but i creates only locally on my computer but i would like to create it on the servers. I think inovke-command wil not work because of the variables that are needed.

    Thanks again.

  • #76543

    Simon B
  • #76545

    Jaapie bakker

    Thanks simon but that not what i am looking for because i have already deployment other scripts on my severs. There has to be a way to do it like i posted above?

  • #76548

    Simon B

    Are your servers in the same OU ?

  • #76552

    Jaapie bakker

    Yes they are, but i would like to manage which servers are about to restart so not all servers in the OU

  • #76555

    Max Kozlov

    Enter-PSSession for interactive use only

    you should use Invoke-Command with $using: variable prefix

    look at example 9 for Invoke-Command

You must be logged in to reply to this topic.