0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

パワーシェル、管理者権限昇格コマンド参考URL

Posted at

パワーシェルの管理者権限昇格のコマンドは以下に書かれてありました
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で起動します。 ついでに現在のスクリプトは終了します

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?