question

Razzi29 avatar image
0 Votes"
Razzi29 asked NewbieJones-6218 commented

Query multiple servers to check local user and rename administrator

I have a hand full of Windows Servers. I need to develop a way to query the local user SAM on each server to check if a username exists. If it does not exist then I need to rename the built-in Administrator account to this username instead OR alternative, leave the Administrator and create new user john and add it to the local administrator group for each server. is there a way I can do this via PS against multiple servers from a text or CSV file?

windows-serverwindows-server-powershellwindows-active-directory
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The answer is yes, but I don't think anyone will just write you a script.

The basic logic is to import the list (Import-CSV)

Pipe that into a ForEach loop.

Within that loop, you will have an IF statement that checks to see if the administration account exists and depending on the result, execute some code to rename the account.

If you attempt this yourself and then post the code, then you are more likely to get assistance (unless someone has a ready to go script with exactly the same requirements).

GPO is the best way to do this for domain joined member servers. Writing lots of code for something that can be defined simply in the GPO seems counter intuitive. Specially if you are not well versed in PowerShell yet.



Need to learn PowerShell?

The following download is free.
https://www.sapien.com/books_training/Windows-PowerShell-4

Start with the first half of the book and do the exercises to cover the basics.
Then work through the 2nd half of the book which covers common tasks.

0 Votes 0 ·
GaryReynolds avatar image
1 Vote"
GaryReynolds answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Razzi29 avatar image
0 Votes"
Razzi29 answered GaryReynolds commented

@GaryReynolds Thanks for providing the suggestion and link. I was hoping to use a PowerShell script to query member servers on a domain from a text file, go through the text file for server names, then check for 2 or 3 specific usernames if they exist then populated a CSV. Any suggestions/ help is much appreciated.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I would suggest you add the windows-server-powershell tag to your question, which should help you find a solution.

Gary.

1 Vote 1 ·