Question: Whats the best/easiest way to test for administrative rights in a PowerShell script?

I need to write a script that requires administrative rights and want to know the best way to achieve it.

Answer: 
In Powershell 4.0 you can use [requires](https://technet.microsoft.com/en-us/library/hh847765(v=wps.630).aspx) at the top of your script:

```
#Requires -RunAsAdministrator

```

Outputs:

> 
> The script 'MyScript.ps1' cannot be run because it contains a "#requires" statement for
>  running as Administrator. The current Windows PowerShell session is not running as Administrator. Start Windows
>  PowerShell by using the Run as Administrator option, and then try running the script again.
> 
> 
>
FYI, for those folks that have the [PowerShell Community Extensions](http://pscx.codeplex.com) installed:

```
PS> Test-UserGroupMembership -GroupName Administrators
True

```

This cmdlet is a bit more generic in that you can test for group membership in any group.