I have a script that queries a Oracl SQL Database for information going back X amount of days and has to be executed only on work days. I have resolved half problem by using a function I found on this forum:
(http://powershell.com/cs/forums/t/11979.aspx)
function IsTodayWorkingDay
{
$today = Get-Date -Format d
if (($today.DayOfWeek -eq [System.DayOfWeek]::Saturday) -or
($today.DayOfWeek -eq [System.DayOfWeek]::Sunday))
{
#weekend today
return $false
}
#Holidays
$holidays ="04/05/2015","25/05/2015","31/08/2015","25/12/2015","28/12/2015","01/01/2016"
if ($holidays -contains $today)
{
#holiday today
return $false
}
#none of the conditions above is met, it must be working day today
return $true
}
If (IsTodayWorkingDay)
{###start this script with SQL query}
Else {Write-Host "It is a holiday"}
As it stands now the scripts runs a query that retrieves information for last 1 day(s). I can change this 1 day to a variable but not sure how to pass the amount of days needed.
As example:
8th of May is Friday and a work day and I know that it has been 1 day since I ran the script with SQL query. So in the SQL query I wold put in 1 day to go back.
9th of May is Saturday and that is a holiday and the script with SQL query will not be executed based on the "IsTodayWorkingDay" function.
11th of May is Monday and a work day and I know that it has been 3 days since I ran the script with SQL query. So in the SQL query I wold put in 3 days to go back.
25th of May is Monday and a Public holiday and the script with SQL query will not be executed based on the "IsTodayWorkingDay" function.
26th of May is Tuesday and a work day and I know that it has been 4 days since I ran the script with SQL query. So in the SQL query I would put in 4 days to go back.
29th Of December is Tuesday and a work day and I know that it has been 5 days since I ran the script with SQL query. So in the SQL query I would put in 5 days to go back. (Xmas)
So I need to calculate the amount of days since the last time the script with SQL query got executed and pass the number of days to SQL query through variable as int.
Any help is much appreciated.