PowerShell Script to get all Local Administrators of all Servers in Domain

TonyJK 876 Reputation points
2020-12-05T10:50:26.38+00:00

Hi,

We can get members of Local Administrators group in all Domain Computers from the following script.
https://gallery.technet.microsoft.com/Query-members-of-Local-d0f393a6

However, we need to get the Local Administrators Group Members for Server only.

From different blogs, we need to add a filter
Get-ADComputer -Filter 'operatingsystem -like "server"

However, we have attempted to amend the script but no luck.

Is there any suggestion ?

Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 109.1K Reputation points MVP
    2020-12-05T12:36:10.317+00:00

    What happens if you modify line 41 in the script of Mahdi Tehrani with this:

    $ComputerName  = (Get-ADComputer -Filter 'operatingsystem -like "*server*" -and enabled -eq "true"' -Server (Get-ADDomain).DNsroot -SearchBase $Path)
    

    I've not tested this, maybe there is a syntax issue. But maybe this will help.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 109.1K Reputation points MVP
    2020-12-05T11:03:14.16+00:00

    Maybe this filter works for you?

    Get-ADComputer -Filter 'operatingsystem -like "*server*"'
    

    It's helpful to see your script and the details what is not working for you.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.