Monday, June 5, 2023

PowerShell: Requiring a Script to Run as Administrator

Placing the following at the top of a PowerShell script requires that said script to run as administrator:

#Requires -RunAsAdministrator

For example, Pester 3.x is installed with modern versions of Windows and only an administrator can uninstall this O.S. integrated version of Pester hence "#Requires -RunAsAdministrator" comes in handy.

The #Requires statement is documented by Microsoft at about_Requires and the comprehensive overview of #Requires provided by Microsoft's documentation is as follows:






No comments :

Post a Comment