locked
Third Firday of the month RRS feed

  • Question

  • I need to reboot a few servers on the 3rd Friday of the month but I'm struggling with the PowerShell commands. Anyone able to assist?
    Friday, August 10, 2018 6:59 AM

All replies

  • There is no command for "3rd Friday".  You hae to start at the first day and count to three.

    The command to restart a computer is "Restart-Computer".

    help restart-computer -online.


    \_(ツ)_/

    Friday, August 10, 2018 7:10 AM
  • Hi,

    Thanks for your question.

    Restart-Computer -ComputerName SRV1,SRV2,SRV3,SRV4 -AsJob

    1. Restart-Computer has an AsJob parameter. It can be used to create a background job using the AsJob parameter. Allowing batch restart tasks to be delivered in the background without having to wait for each server to restart. You can use it.

    Also you can learn something from the link below.

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-computer?view=powershell-6

    2. If you want to run the script on the specific day of a month(in automatically),you can use Task Scheduler to run the script automatically on the 3rd Friday of the month. 

    Refer to the following link:

    https://social.technet.microsoft.com/wiki/contents/articles/38580.configure-to-run-a-powershell-script-into-task-scheduler.aspx 

    Best Regards,

    Lee


    Just do it.


    Friday, August 10, 2018 10:20 AM
  • The 3rd Friday of every month can only fall on the days of 15 through 21, and there can only be one Friday of the month in that range.  In that case all you need to do is test for "Friday" AND "15-21'. 

    You could schedule this job to run every day - it will run your restart script/code on the 3rd Friday of every month or exit if not.

    $Today = Get-Date
    
    If ($Today.DayofWeek -eq 'Friday' -and $Today.Day -ge '15' -and $Today.Day -le '21') 
    {
    Write-Host "Today is the 3rd Friday of the month, execute restart."
    Invoke-Command {.\Restart-Computer $SERVER}
    }
    
    Else
    {
    Write-Host "Today is not the 3rd Friday of the month; exit."
    Exit
    }
    

    Friday, August 10, 2018 11:47 AM
  • The task scheduler can schedule by third Friday of month.


    \_(ツ)_/

    Friday, August 10, 2018 3:35 PM