PowerShell Version 4 New Feature: Requires Statements Now Let Users Require Administrator Access Rights If Needed

In PowerShell version 4, there’s a new RunAsAdministrator option for the Requires statement that prevents a script from executing unless PowerShell is running as an administrator.

The information about this new option from the PowerShell version 4 about_Requires help topic is shown in the following image. To learn more about the requires statement, run help about_requires from PowerShell.

ps4-requiresadmin-help.png

Here’s the message that’s displayed if this option is specified and the person running the script is not an administrator:

ps4-requiresadmin.png

Previously, you had to use the .NET Framework to determine if PowerShell was running as an administrator. Here’s a snippet of how this was accomplished in previous versions of PowerShell:

ps3-requiresadmin.png

µ