From a2e0888013ec7414fc49347bdcad9042790adff8 Mon Sep 17 00:00:00 2001 From: Gabe Date: Tue, 5 Aug 2025 15:12:32 +0000 Subject: [PATCH] Upload files to "Test Scripts" --- .../Test - Find last week of month.ps1 | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Test Scripts/Test - Find last week of month.ps1 diff --git a/Test Scripts/Test - Find last week of month.ps1 b/Test Scripts/Test - Find last week of month.ps1 new file mode 100644 index 0000000..aded1ff --- /dev/null +++ b/Test Scripts/Test - Find last week of month.ps1 @@ -0,0 +1,53 @@ +<# +Author: Gabe Kerntke +Company: UFS LLC +Date: 03-12-2025 + +.Synopsis + +.Modified +2025-03-12 (GabeK) - Original script created + +#> + +# Variables # +$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem +# Functions # + +# Start Script # +If ($osInfo.ProductType -ne "1") { + $Date = Get-Date -DisplayHint Date + $GetLastDay = New-Object DateTime($Date.Year, $Date.Month, [DateTime]::DaysInMonth($Date.Year, $Date.Month)) + $LastDay = $GetLastDay #.ToString("dddd, MMMM d, yyyy") + $SecondLastDay = $LastDay.AddDays(-1) + $ThirdLastDay = $LastDay.AddDays(-2) + $ForthLastDay = $LastDay.AddDays(-3) + $FifthLastDay = $LastDay.AddDays(-4) + $SixthLastDay = $LastDay.AddDays(-5) + $SevenLastNight = $LastDay.AddDays(-6) + + $Array = @( + $LastDay, + $SecondLastDay, + $ThirdLastDay, + $ForthLastDay, + $FifthLastDay, + $SixthLastDay, + $SevenLastNight + ) + + $excludeValues = "Saturday", "Sunday" + $filteredArray = $array | Where-Object { $_.DayOfWeek -notin $excludeValues } + + If ($Date -in $filteredArray) { + Write-Host "do not reboot" + Exit + } + Else { + Write-Host "can reboot" + #Restart-Computer -Force + } +} +Else { Write-Host "Device is not a server, exiting script." } + +# End Script # \ No newline at end of file