almost got FORCE_ME_OFF workan rght

This commit is contained in:
2025-09-27 07:51:21 -06:00
parent 690d6557ff
commit 8915e2de25
+44 -26
View File
@@ -1,49 +1,65 @@
# usage force_me_off -Hours <int> -Minutes <int> -GraceMinutes <int> # usage force_me_off -Hours <int> -Minutes <int> -GraceMinutes <int>
# default one hour, zero minutes, zero grace minutes # default one hour, zero minutes, one grace minute
param ( $Hours=1, $Minutes=0, $GraceMinutes=0 ) param (
[int]$Hours,
[int]$Minutes,
[int]$GraceMinutes
)
# handle defaULTS, not using normal param() method because wasnt workan right
## !skillissue
if($Hours -eq $null) {
$Hours = 1
} elseif($Minutes -eq $null) {
$Minutes = 0
} elseif ($GraceMinutes) {
$GraceMinutes = 1
}
# some calcs # some calcs
$wait_minutes = (($Hours*60)+$Minutes) $wait_minutes = (($Hours*60)+$Minutes)
$total_wait_minutes = ($wait_minutes+$GraceMinutes) $total_wait_minutes = ($wait_minutes+$GraceMinutes)
$total_wait_seconds = ($total_wait_minutes*60) $total_wait_seconds = ($total_wait_minutes*60)
$reboot_time = $((Get-Date).AddHours($Hours).AddMinutes($Minutes + $GraceMinutes).ToString("hh:mm:ss tt")) $reboot_time = $((Get-Date).AddHours($Hours).AddMinutes($Minutes + $GraceMinutes).ToString("hh:mm:ss tt"))
function ForceOff {
# time wasters
## checks C drive after reboot to waste time and fix errors
## chkdsk /r C: # as admin
chkdsk /r C:
pause # pause for clarity
# Do the sleep $args_string = "-Hours $Hours -Minutes $Minutes -GraceMinutes $GraceMinutes"
Start-Sleep -Seconds $total_wait_seconds # echo $args_string
# exit
# do reboot # function ForceOff {
## schedule shutdown # # time wasters
## redundant but also for warnings # ## checks C drive after reboot to waste time and fix errors
### reboot (-r) forced (-t) in seconds (-t) # ## chkdsk /r C: # as admin
shutdown -r -f -t ($total_wait_seconds+10) # 10 second bonus to defer to Start-MpWDOScan # chkdsk /r C:
## Start Windows Defender Offline Scan # pause # pause for clarity
## wastes time #
## does the actual reboot # # Do the sleep
Start-MpWDOScan # Start-Sleep -Seconds $total_wait_seconds
} #
# # do reboot
# ## schedule shutdown
# ## redundant but also for warnings
# ### reboot (-r) forced (-t) in seconds (-t)
# shutdown -r -f -t ($total_wait_seconds+($GraceMinutes*60)) # 10 second bonus to defer to Start-MpWDOScan
# ## Start Windows Defender Offline Scan
# ## wastes time
# ## does the actual reboot
# Start-MpWDOScan
# }
# force admin and disable previously scheduled shutdown # force admin and disable previously scheduled shutdown
# environment # environment
## Check for administrator privileges ## Check for administrator privileges
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
# Restart with elevated privileges # Restart with elevated privileges
Start-Process pwsh.exe -Verb RunAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`" $($args -join(' '))" Start-Process pwsh.exe -Verb RunAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`" $args_string"
exit exit
} }
$args_string = "-Hours $Hours -Minutes $Minutes -GraceMinutes $GraceMinutes"
Write-Host "args: $args_string, wait_minutes: $wait_minutes, total_wait_minutes: $total_wait_minutes, total_wait_seconds: $total_wait_seconds" Write-Host "args: $args_string, wait_minutes: $wait_minutes, total_wait_minutes: $total_wait_minutes, total_wait_seconds: $total_wait_seconds"
# Write-Host "-File `"$($MyInvocation.MyCommand.Path)`" $args_string" # Write-Host "-File `"$($MyInvocation.MyCommand.Path)`" $args_string"
# pause # cleanup
# exit
## clean up any sched backups ## clean up any sched backups
shutdown -a shutdown -a
@@ -69,7 +85,9 @@ echo y | chkdsk /r C:
## schedule normal shutdown as backup and for warnings ## schedule normal shutdown as backup and for warnings
shutdown -f -r -t ($total_wait_seconds+10) # 10 second bonus to defer to Start-MpWDOScan shutdown -f -r -t ($total_wait_seconds+10) # 10 second bonus to defer to Start-MpWDOScan
## do the actual reboot by triggerinmg Start-MpWDOScan ## do the actual reboot by triggerinmg Start-MpWDOScan
Start-Sleep -Seconds ($Seconds+60) && Write-Host "Start-MpWDOScan" && webhook "REBOOTAN <@&1369280290203373670>" # Start-Sleep -Seconds ($Seconds+60) && Write-Host "Start-MpWDOScan" && webhook "REBOOTAN <@&1369280290203373670>" & # also fork it to the background to be a gremlin
Start-Sleep -Seconds ($total_wait_seconds+60) && Start-Process pwsh && webhook "REBOOTAN <@&1369280290203373670>" & # also fork it to the background to be a gremlin
pause
# $test_background_scriptblock = { # $test_background_scriptblock = {
# Write-Host $total_wait_seconds # Write-Host $total_wait_seconds