none
Delete Local Accounts on remote clients in multi-domains RRS feed

  • Question

  • Hey Guys,

    Need some help here....I just inherited a multi-domain environment (10 domains). I need to delete specific local accounts on remote clients in each of these domains. Usually, I would just use the:

    net user userid /delete

    However, I have 200 clients and would rather not do this each time. How would I write a simple script using net user userid /delete to call a server.txt file or user.txt file?

    Friday, January 27, 2017 8:13 PM

Answers

  • Hey Guys,

    Need some help here....I just inherited a multi-domain environment (10 domains). I need to delete specific local accounts on remote clients in each of these domains. Usually, I would just use the:

    net user userid /delete

    However, I have 200 clients and would rather not do this each time. How would I write a simple script using net user userid /delete to call a server.txt file or user.txt file?

    Here's something quick and dirty that I just wrote:

    #Just create a users.txt file and place it in the same directory as this script
    $users = get-content .\users.txt
    
    #Remove the hash in front of the below line to use servers.txt, if you want
    #servers = get-content .\servers.txt
    
    #Loop through all of the users in the $users variable
    foreach($user in $users){
        #Remove each one of the users
        net user $user /delete
    }


    Cheers,

    Ryan

    Microsoft Server Engineer

    Blog:   Twitter:   LinkedIn:   

    Please remember to mark the replies as answers if they help.

    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

    Friday, January 27, 2017 8:45 PM

All replies

  • So you may not be aware that this forum is for specific questions rather than "can someone write a script for me?" (See the very first post from the top of this forum.)

    With that said, what have you tried so far, and with what results?


    -- Bill Stewart [Bill_Stewart]

    Friday, January 27, 2017 8:36 PM
    Moderator
  • Hey Guys,

    Need some help here....I just inherited a multi-domain environment (10 domains). I need to delete specific local accounts on remote clients in each of these domains. Usually, I would just use the:

    net user userid /delete

    However, I have 200 clients and would rather not do this each time. How would I write a simple script using net user userid /delete to call a server.txt file or user.txt file?

    Here's something quick and dirty that I just wrote:

    #Just create a users.txt file and place it in the same directory as this script
    $users = get-content .\users.txt
    
    #Remove the hash in front of the below line to use servers.txt, if you want
    #servers = get-content .\servers.txt
    
    #Loop through all of the users in the $users variable
    foreach($user in $users){
        #Remove each one of the users
        net user $user /delete
    }


    Cheers,

    Ryan

    Microsoft Server Engineer

    Blog:   Twitter:   LinkedIn:   

    Please remember to mark the replies as answers if they help.

    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

    Friday, January 27, 2017 8:45 PM
  • Bill,

    My apologies for posting in the wrong forum. I am a novice at scripting. I am not looking for someone to write a script for me and say "hey here you go"...I'm just looking for some pointers here and there....Thanks...

    Friday, January 27, 2017 9:17 PM
  • Ryan,

    Thanks...I wasn't sure how to create that loop. Much appreciated..

    Friday, January 27, 2017 9:19 PM
  • Ryan,

    Thanks...I wasn't sure how to create that loop. Much appreciated..

    No problem! Make sure to mark my reply as answer if you see fit. 



    Cheers,

    Ryan

    Microsoft Server Engineer

    Blog:   Twitter:   LinkedIn:   

    Please remember to mark the replies as answers if they help.

    Note: Posts are provided “AS IS” without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

    Friday, January 27, 2017 9:22 PM