PowerShell Script – Are we running as Admin?

While exploring some of the new cmdlets that come with Windows 8.1 I came across Test-NetConnection. and noticed that it has a property called IsAdmin. When running the cmdlet in an elevated PowerShell session the property returns True otherwise False. So I put together a very simple script to check whether we are running as admin or not.

<#
.Synopsis
   Checks if we run as administrator
.DESCRIPTION
   This script uses the Test-NetConnection cmdlet that contains a IsAdmin Property to check if we ar running as admin
.EXAMPLE
   Check-Admin.ps1
#>

$AmIAdmin = Test-NetConnection localhost 
 if ($AmIAdmin.IsAdmin -eq "True") {write-host "Running as Admin"} Else {write-host "NOT Running as Admin"}

Other (and probably more reliable) ways to determine whether we are running as admin are described here by Ed Wilson and here by Ben Armstrong.

One Reply to “PowerShell Script – Are we running as Admin?”

Leave a Reply