43 lines
1.7 KiB

# This code was published by Benjamin Armstrong on
# This script will open an elevated powershell terminal and will run the specified script
# The script(s) that must be run with elevated privileges must be configured on the last lines
# Get the ID and security principal of the current user account
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole))
# We are running "as Administrator" - so change the title and background color to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
$Host.UI.RawUI.BackgroundColor = "DarkBlue"
# We are not running "as Administrator" - so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
# Specify the current script path and name as a parameter
$newProcess.Arguments = $myInvocation.MyCommand.Definition;
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
# Exit from the current, unelevated, process
# Run your code that needs to be elevated here
# Will run rds_licenses script from check_mk directory
& "C:\Program Files (x86)\check_mk\rds_licenses_2012.ps1"