We’ve set out to help a customer with automation within their IT department.
By creating scripts and cmdlets the Helpdesk-team frequently occurring tedious tasks.
Some tasks requires an elevated prompt, there is no way around it. But it’s not obvious how to check if the current prompt is elevated, or how to elevate the session.
You can run this block to check if the current session is elevated.
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
Echo "This script needs to be run As Admin"
By running this one-liner you can elevate the a PowerShell session.
Start-Process powershell -Verb runAs