Skip to content

Instantly share code, notes, and snippets.

@cwg999
Created August 5, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwg999/8b2b7674b6b524ad350d1d512e3004a5 to your computer and use it in GitHub Desktop.
Save cwg999/8b2b7674b6b524ad350d1d512e3004a5 to your computer and use it in GitHub Desktop.
Renaming PDF's Script --- Count Estimated Progress by Working Days
# $folderPath = "C:\temp\"
Write-Host "Running!"
$file_count = 32963#[System.IO.Directory]::GetFiles($folderPath, "*.pdf", 1).Count # this should remain pretty constant
$file_count_R = [System.IO.Directory]::GetFiles($folderPath, "*R_*.pdf", 1).Count
Write-Host "Total Files: ":$file_count
Write-Host "Progressed Files: ":$file_count_R
### Capture the holidays in a HashTable
### Could have used an array but thought I might need the name of the holiday eventually
$Holidays = @{
"New Year's Day" = Get-Date 'Jan 1'
"Martin Luther King, Jr. Day" = Get-Date 'Jan 21'
"Presidents' Day" = Get-Date 'Feb 18'
"Memorial Day" = Get-Date 'May 27'
"Independence Day" = Get-Date 'Jul 4'
"Labor Day" = Get-Date 'Sep 2'
"Thanksgiving Day" = Get-Date 'Nov 28'
"Day After Thanksgiving" = Get-Date 'Nov 29'
"Christmas Day" = Get-Date 'Dec 25'
}
### Initialize the number of working days (this turns out to be my ideal)
$workingDays = 0
### Set the Starting Month/Day
$StartMonth = 8
$EndMonth = [DateTime]::Today.Month
$StartDay = 2
$EndDay = [DateTime]::Today.Day
### Get the number of days in the month
### Count the days in the month, excluding weekends and holidays
for ($month = $StartMonth; $month -le $EndMonth; $month++ )
{
$DaysInMonth = [DateTime]::DaysInMonth([DateTime]::Today.Year,$Month)
if($month==$EndMonth){
$endDay = $DaysInMonth
}else{
$endDay = $EndDay
}
for ($day = $StartDay; $day -le $endDay; $day++)
{
if (([DateTime]"$Month $day").DayOfWeek -in @('Saturday','Sunday'))
{
# Write-Verbose "Weekend! $Month $day"
}
elseif($Holidays.ContainsValue([DateTime]"$Month $day"))
{
# Write-Verbose "Holiday! $Month $day"
}
else
{
# Write-Host $month"/"$day
$workingDays++
}
}
}
### Spew the output
Write-Host "Target Files Completed By Today:"((($workingDays)/40)*$file_count)
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host
Write-Host "Finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment