![見出し画像](https://assets.st-note.com/production/uploads/images/116105020/rectangle_large_type_2_ced34c8ada3c65a9850059e9463982f6.png?width=1200)
PowerShell 管理者権限に昇格して実行
PowerShellを使うときは設定を変更するとか
情報を取り出すとかで使うことが多いと思うのですが
ほとんどの場合、管理者権限が無いと何もできません。
そのようなときのPowerShellを管理者権限に昇格して実行したいときのメモです。
PowerShellを立ち上げて、以下のコマンドを入力
Start-Process powershell -verb runas
ps1ファイルを実行時に自動的に昇格させたいときは
スクリプトの先頭にこれを挿入する
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole("Administrators")) { Start-Process powershell.exe "-File `"$PSCommandPath`"" -Verb RunAs; exit }
他にもVBSの中から管理者権限でps1ファイルを実行する手もあります。
でもVBSはマイクロソフトから非推奨になりましたからPowerShellないで管理者に昇格するほうがいいかも
関連記事もどうぞ
#PowerShell #プログラミング #プログラミング学習 #Windows #情シス #社内SE #管理者権限に昇格