やりたいこと ●PowerShellスクリプトファイル(.ps1ファイル)を右クリックで「PowerShellで実行」したときに、自動的に管理者権限として実行する。 ※もちろん、バッチファイル(.bat形式)のファイルなどからその.ps1ファイルを呼び出して実行する場合でも管理者権限になります。 ●上記を、「.ps1ファイル」のソースの先頭に1行追加するだけで実現する。 スクリプト例 if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs; exit } 解説 使い