Powershell Script to Delete Local Users on a Standalone Server

I need to create a script in PowerShell that will delete local user accounts from a CSV File. This is for a standalone server that is not on a domain.

Any help would be greatly appreciated.
Thanks
apusjellisAsked:
Who is Participating?
 
Chris DentPowerShell DeveloperCommented:
Good afternoon,

It's actually quite easy.

How's your CSV formatted? If we assume it's like this:
Server,Username
server1,user1
server1,user2
server2,user1

Open in new window

Then we can do this:
Import-Csv YourFile.csv | ForEach-Object {
  ([ADSI]"WinNT://$($_.Server)").Invoke("Delete", "user", $_.Username)
}

Open in new window

In the example above, "Delete" and "user" are static values and should not be changed.

HTH

Chris
0
 
apusjellisAuthor Commented:
n
0
 
apusjellisAuthor Commented:
Thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.