How to check if a user is an administrator for a given server name?

trong2001 21 Reputation points

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 Test-Administrator
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,107 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. Yuhan Deng 3,761 Reputation points Microsoft Vendor

    You might want to refer to this article:
    Also PowerShell version higher than 5.1 (Windows Server 2016) contains Get-LocalGroupMember cmdlet.
    $user = "$env:COMPUTERNAME\$env:USERNAME"
    $group = 'Administrators'
    $isInGroup = (Get-LocalGroupMember $group).Name -contains $user

    Thanks for your time.
    Best regards,

    If the Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  2. Dave Patrick 426.1K Reputation points MVP

    Just checking if there's any progress or updates?

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments