Powershell script to get the local adminstrators liston multiple windows servers

  • santu4bth

    SSC Enthusiast

    Points: 121

    Hi

     

    Could you please provide a PowerShell script to loop through multiple servers and get the list of local administrators of all servers?

    invoke-command {net localgroup administrators} -comp <servername>

    The above powershell command lists from one server.

    please provide a script to run on multiple servers.

     

    Thanks

    San

     

     

     

  • Sue_H

    SSC Guru

    Points: 89874

    If you do a quick search on google, you will find a lot of examples - my first page has over a dozen links with examples:

    Search of: run powershell command on multiple servers

     

    Sue

  • Joie Andrew

    One Orange Chip

    Points: 27271

    You know you can provide a comma separated list to the -computername parameter, right?

    Type the NETBIOS name, IP address, or fully qualified domain name of one or more computers in a comma-separated list. To specify the local computer, type the computer name, localhost, or a dot (.).

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-6#parameters

    Joie Andrew
    "Since 1982"

  • Jeff Moden

    SSC Guru

    Points: 993867

    To answer the logically next expected question...

    https://www.google.com/search?&q=save+powershell+output+to+table+in+sql+server

    Of course, I don't have a code example for this because I don't use PowerShell to do such things, especially since the list of my servers is stored in SQL Server to begin with.  Although a lot of people frown on it because of misunderstanding, basic lack of knowledge on the subject, and visceral fear, I use xp_CmdShell for this type of thing.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
    "If you think its expensive to hire a professional to do the job, wait until you hire an amateur."--Red Adair
    "Change is inevitable... change for the better is not."
    When you put the right degree of spin on it, the number 3|8 is also a glyph that describes the nature of a DBAs job. 😉

    Helpful Links:
    How to post code problems

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply