Combreal

ContinueScriptAfterReboot.ps1

Dec 8th, 2020
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (-Not (Test-Path "C:\Temp\tik.txt" -PathType leaf))
  2. {
  3.     New-Item "C:\Temp\" -Name "tik.txt" -ItemType "file"
  4.     $RunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce"
  5.     $ScriptPath = $MyInvocation.MyCommand.Definition
  6.     $ScriptExecPath = "C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -File "
  7.     $ScriptFullExecPath = $ScriptExecPath + $ScriptPath
  8.     Set-ItemProperty $RunOnceKey "NextRun" $ScriptFullExecPath
  9.     #Do first part of stuff here
  10.     Restart-Computer
  11. }
  12. else
  13. {
  14.     Remove-Item "C:\Temp\tik.txt"
  15.    
Add Comment
Please, Sign In to add comment