パワーシェルの管理者権限昇格のコマンドは以下に書かれてありました
https://qiita.com/sakekasunuts/items/63a4023887348722b416
●パワーシェル起動後下記実行
Start-Process powershell -verb runas
Start-Process powershell PowerShellを新しく始めます
-Verb RunAs 管理者権限で
●ps1実行時に自動的に昇格させたい↑
スクリプトの頭にこれを挿入する
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { Start-Process powershell.exe "-File "$PSCommandPath
"" -Verb RunAs; exit }
if ( ! ( ~~~ ) ) もし(~~~)でなければ
[Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]
::GetCurrent() 現在の実行権限を確認
.IsInRole("Administrators") 管理者権限
Start-Process powershell.exe PowerShellを新しく始めます
"-File "$PSCommandPath
" 私自身のフルパスを指定します
-Verb RunAs 管理者権限で
; exit 現在のスクリプトを終了します。
直訳すると
現在の実行権限を確認します。もし管理者権限でなければ、 同じスクリプトを新たな管理者権限のPowerShellで起動します。 ついでに現在のスクリプトは終了します