PowerShell: Test if running as admin

If you need to run something as the local admin then you can test for that. See below:

function Test-Administrator  
    $User = [Security.Principal.WindowsIdentity]::GetCurrent();
    return (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)  

If you're not admin it returns 'False'.

And you will never guess what it brings back if you are an admin user...

Edit: Some neckbeard on Reddit accused me of stealing this code, which I absolutely did not. However in the interest of playing fair here are some other sources where you could find something similar to this. (Sources provided by Mr NeckBeard.)

How to check if a user is an administrator for a given server name? - Microsoft Q&A
Using the username, I want to find a way to check if that user is an administrator for a given remote server. I found the following function online but it only checks if the user is an admin for the local machine. Any help is appreciated! function…