Let’s see how codeblocks look in this first post. Below is a block I’ve used in the past to elevate interactive PowerShell scripts.
# Elevate to admin
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
#"No Administrative rights, it will display a popup window asking user for Admin rights"
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments
set-executionpolicy -scope CurrentUser -executionPolicy Bypass
break
}
# code here