• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 59
  • Last Modified:

Powershell : Compute working days without we and holidays

Powershell  : script to compute working days (for ex +5 days) from date xxxx with excluded holidays days (based on list).

anybody has this available ?

Tks !
François VDC
François VDC
1 Solution
NorieVBA ExpertCommented:
Do you want to get the date N working days from date XXXX?
something like this, but in function form?
$a = [DATETIME]'2/2/2018'
while($foundworkdays -lt $workdays) { 
    if (('Saturday', 'Sunday') -notcontains $a.AddDays($offset).dayofweek) {$foundworkdays++}

Open in new window

François VDCIcT service DeskAuthor Commented:
anybody ?
anybody ?
Did you read my comment?
Sajen JoseCommented:
I am not sure if this is what you are looking for:


#Holiday List - Keep adding Holidays and then add thos variables into the $Holidays Array
[DateTime]$HOL01 = "01/02/2018"
[DateTime]$HOL02 = "02/01/2018"

$Holidays = @($HOL01, $HOL02)

Function WorkingDays
    $Weekends = [System.DayOfWeek]::Saturday, [System.DayOfWeek]::Sunday #Weekends
    #Change the day, month and Year based on your values, the start date from which you want to calculate
    $StartDate = Get-Date -Year 2018 -Month 1 -Day 1 
    $ToDate = (Get-Date).AddDays(-1)

    $WorkDays = 0

    while ($StartDate -le $ToDate) {
        $StartDate = $StartDate.AddDays(1)

        If(($StartDate.DayOfWeek -notin $Weekends) -and ($StartDate.Date -notin $Holidays))


#Call the function to execute

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now