Calculate the first working day after N vacation days

…this post was published on 2015 October 20.

This time , we calculate the first working day after N free days. The script need the .csv file as in the previous post.

You should provide the file’s name, start-date  and the number of free days

<# .Synopsis Get total number of week days .Description Return the number of days between two dates not counting Saturday and Sunday. .Parameter File The csv file with Hollydays .Parameter Start The starting date .Parameter Days The number of free days .Example PS C:\> Get-TotalWeekDays -file ./Hollydays.csv -start 7/1/2012 -days 20
Romeo Donca
Param (
[Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$true,HelpMessage=”what is the csv file name?”)]
[Parameter(Position=1,Mandatory=$True,ValueFromPipeline=$true,HelpMessage=”What is the start date?”)]
[Parameter(Position=2,Mandatory=$True,ValueFromPipeline=$true,HelpMessage=”What is the number of free days?”)]
Function Get_LastHollyDay()

#read the csv file and store it in $hollydays
$hollydays = Import-Csv $file
#define new array with working days from hollydays
#get this array’s elements
$notworkingdaysnumber =$notworkingdays.Length
foreach ($data in $hollydays){
if (([datetime]$ -notmatch “Sunday|Saturday”){
$notworkingdays += $
$notworkingdaysnumber = $notworkingdays.Length
#define a counter
# Add day by day to Start value
if ( ($notworkingdays -contains (get-date $end -Format MM.dd.yyyy)) -match $false){
if ( $end.Date.DayOfWeek -match “Sunday|Saturday”){
$end =$end.AddDays(1)
while ($i -le $days)
$end =$end.AddDays(-1)
” First Vacation Day: $($start.ToShortDateString())”
” First Working Day:$($end.DayOfWeek) – $($end.ToShortDateString())”
} #end function
This entry was posted in Coding, Powershell. Bookmark the permalink.