1

I am trying to check my remote windows server 2012 R2 machines for admin rights to the current user via Ansible scripts. I found the following command to check for admin rights on the internet:

([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

Now a few questions regarding this:

1) This command is giving 'false' as output when i RDP into any system with the admin account. But the same command return 'true' when i run it via Ansible (Ansible uses winRM to fire commands from a central server).

2) Is there a better command (CMD or powershell) to check if the current user has admin rights ?

1 Answer 1

2

Your command always returns true for me when running in an RDP session as an elevated admin. Make sure to run your PowerShell as admininistrator

When using winRM or Enter-PsSession you are automatically elevated.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .