Show users within a domain who have Local Admin Accounts

I am trying to create a Powershell script that will export all the users within a domain who have a local admin account into a .CSV or .TXT file. I was wondering if anyone had a script like this already.

I think I can see how to get this information for individual machines… something like this:

Invoke-Command -ComputerName pc2 -ScriptBlock{Get-LocalGroupMember -Name ‘Administrators’}

I’ve experimented a bit looking at getting domain admin accounts for users using the Invoke command, however getting local admin accounts is going to be slightly different.

Any assistance greatly appreciated.

Rob,
Welcome to the forum. :wave:t4:

Have you tried to search for it? Something like this is a very common task. It has been asked many times and it has been answerd many times already. Please use your prefered internet search engine to search for examples you can adapt to your particular needs.

In genereal this forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

The cmdlet Invoke-Command can take arrays for the parameter -ComputerName. This way you can query more than one computer at a time. But these computers need to be reachable in your infrastructure and you have to have administrative rights.

BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink: