Home >
Windows にまつわる e.t.c.
PowerShell が管理権限で実行されているか確認する
PowerShell で処理をする場合、管理権限が必要なことが多いです。
管理権限を持っていない状態でスクリプトを実行してエラーになってしまった残念経験はだれしもあるでしょう。
そんな事にならないよう、現在管理権限を持っているか否かを判定する関数書きました。
管理権限を持っていたら $true が帰ってきます。
#######################################################
# 管理権限で実行されているか確認
#######################################################
function HaveIAdministrativePrivileges(){
$WindowsPrincipal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
$IsRoleStatus = $WindowsPrincipal.IsInRole("Administrators")
return $IsRoleStatus
}
|
関連情報
管理権限で実行
http://www.vwnet.jp/Windows/PowerShell/runas.htm


Copyright © MURA
All rights reserved.