Created
October 31, 2012 14:12
-
-
Save ebibibi/3987231 to your computer and use it in GitHub Desktop.
Windowsを強制的に再起動した上で、次回ログオン時に指定したPowerShellスクリプトを1度だけ実行させます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #第一引数にスクリプト名をフルパスで記述 | |
| #第二引数以降にスクリプトへの引数(複数指定可能) | |
| $RegRunOnceKey = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce" | |
| $powershell = (Join-Path $env:windir "system32\WindowsPowerShell\v1.0\powershell.exe") | |
| $restartKey = "Restart-And-RunOnce" | |
| $script = $args[0] | |
| $newArgs = "" | |
| for($i = 1; $i -le $args.Length; $i++) | |
| { | |
| $newArgs += " " + $args[$i] | |
| } | |
| #RunOnceキーにセット | |
| Set-itemproperty -path $regrunoncekey -name $restartkey -value "$powershell $script$newargs" | |
| Restart-Computer -Force | |
| exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment