Powershell

My collection of favorite PowerShell scripts

Reboot (3am) oneliner:

1
shutdown /r /f /t ([math]::Round(((New-TimeSpan -start (get-date).AddDays(-1) -end (get-date -hour 03 -minute 0 -second 0 -format "HH:mm:ss"))).TotalSeconds))

Reboot w/Scheduled task

1
2
3
4
5
6
7
$action =
New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile
-WindowStyle Hidden -command "& {Restart-Computer -Force -wait}"'
$trigger =
New-ScheduledTaskTrigger -Once -At 3am
Register-ScheduledTask
-Action $action -Trigger $trigger -TaskName 'ScheduledReboot'

Find last reboot

1
get-eventlog System | where-object {$_.EventID -eq "6005"} | sort -desc TimeGenerated