Tip : Is Your PowerShell Session Running With Administrative Privileges?

Sometimes you may need to perform administrative stuff within your script. In such cases, it’s better to check whether your user has such privileges to execute the script.

Please find the sample below, which checks user for administrative privilege;

$user = [Security.Principal.WindowsIdentity]::GetCurrent()

if((New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)){
  # Keep executing your script...
}else{
  # Warn user for required privileges...
  Write-Warning "Please execute the script with administrative privileges."
}

Related posts:

  1. Tip : PowerShell Oturumu Sistem Yöneticisi Olarak Mı Başlatılmış?
  2. AppFabric Cache Management cmdlet
  3. PowerShell ile AppFabric Cache Yönetimi
Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!

Leave a Reply