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 VDCIcT service DeskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.