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:



April 2, 2010 









Android işletim sistemli cep telefonunuz var, peki Enterprisecoding Android uygulamasını denediniz mi? Enterprisecoding web sitesini her yerden takip edebileceğiniz, offline
No comments yet... Be the first to leave a reply!