Author Posts

July 21, 2017 at 6:18 pm

When I run this on several laptops logged in as local admin the value comes back true. I have one laptop that when I am logged in as local admin the value comes back false. Can anyone give me ideas on where to begin to troubleshoot his issue.

$Identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
$Principal.IsInRole([System.Security.Prinicipal.WindowsBuiltInRole]::Administrator)

July 21, 2017 at 10:53 pm

You have a typo in your code. It should not work anywhere actually ... 😉
In line 3 it should be [System.Security.Principal.WindowsBuiltInRole] instead of [System.Security.Prin_i_cipal.WindowsBuiltInRole]

July 24, 2017 at 6:52 pm

Apologies on the typo. But what I am trying to understand is how come when I am logged in as local admin and I run this code the result comes back as false. Is there a way to check if user is a member of local admin and run with elevated privledges.

$Identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$Principal = New-Object System.Security.Principal.WindowsPrincipal($Identity)
$Principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)

July 24, 2017 at 11:17 pm

It seems to me that your problem is not related with Powershell scripting.