diff --git a/Windows-Scripts/force_me_off.ps1 b/Windows-Scripts/force_me_off.ps1 index 80b3d12..37426e4 100644 --- a/Windows-Scripts/force_me_off.ps1 +++ b/Windows-Scripts/force_me_off.ps1 @@ -21,43 +21,19 @@ $wait_minutes = (($Hours*60)+$Minutes) $total_wait_minutes = ($wait_minutes+$GraceMinutes) $total_wait_seconds = ($total_wait_minutes*60) $reboot_time = $((Get-Date).AddHours($Hours).AddMinutes($Minutes + $GraceMinutes).ToString("hh:mm:ss tt")) - $args_string = "-Hours $Hours -Minutes $Minutes -GraceMinutes $GraceMinutes" -# echo $args_string -# exit - -# 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 -# 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 # environment ## Check for administrator privileges if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { # Restart with elevated privileges + ## added the args string Start-Process pwsh.exe -Verb RunAs -ArgumentList "-File `"$($MyInvocation.MyCommand.Path)`" $args_string" exit } -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 "args_string: $args_string, wait_minutes: $wait_minutes, total_wait_minutes: $total_wait_minutes, total_wait_seconds: $total_wait_seconds" # cleanup ## clean up any sched backups @@ -83,25 +59,9 @@ echo y | chkdsk /r C: # shutdown tasks ## 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+60) # add a bonus 60 seconds to favor the Start-MpWDOScan ## do the actual reboot by triggerinmg Start-MpWDOScan # 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 = { -# Write-Host $total_wait_seconds -# Start-Sleep -Seconds 5 -# Start-Process "pwsh.exe" -Verb RunAs -# } - -# $command_string = "-NoExit", "-WindowStyle", "Hidden", "-Command", "& { $background_scriptblock }" -# $test_command_string = "-Command ", "& { $test_background_scriptblock }" - -# Write-Host $test_command_string - -# send it to background! - - -# Start-Process pwsh -ArgumentList $command_string -Verb RunAs -# Start-Process -FilePath "pwsh.exe" -ArgumentList $test_command_string -Verb RunAs \ No newline at end of file +Start-Sleep -Seconds ($total_wait_seconds) && Start-Process powershell -WindowStyle Hidden && webhook "REBOOTAN <@&1369280290203373670>" & # also fork it to the background to be a gremlin +# optional pause +pause \ No newline at end of file