Files
Powershell-Scripts/Test Scripts/Test - Find last week of month.ps1
2025-08-05 15:12:32 +00:00

53 lines
1.3 KiB
PowerShell

<#
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 #