Need Help with Best way to check if local user account exists

Discussion in 'Scripting' started by Ted, May 18, 2005.

  1. Ted

    Ted Guest

    I am in process of writing a script that will create local accounts on a
    domain pc (via group policy computer startup script) which will have three
    parts to it. Just so you know, I am not trying to recreate active directory
    or anything like that, rather the purpose is to have uniform local accounts
    (one admin, one for the workstation admins and an emergency admin one) across
    our 300+ pcs. The first part will check to see if the local user accounts
    already exist, the second part checks group membership to see if they are
    part of the admin group (and then puts tthem there if they are not) and the
    third part checks that the password is what is supposed to be (or changes it
    to what it should be). I have the last 2 parts working fine, but am having a
    problem finding a way to check and see if the local user already exists. The
    only method that I have come up with was to use error checking by trying to
    create the account no matter what and having it error and move on if it is
    already there. I really would rather do this a cleaner way if there is one. I
    did also try a wmi call to the win32_user property after binging to the local
    computer, but it ended up enumerating the domain users group on the pc, so
    that's a no go also.
    Any Help would be greatly appreciated.

    Thanks,

    Ted
     
    Ted, May 18, 2005
    #1
    1. Advertisements

  2. Ted wrot:

    Perhaps attempt to bind to the local user object and trap the error if the
    object does not exist. There will be a timeout, but this still seems faster
    than enumerating all users and checking if the one you seek is among them.
     
    Richard Mueller [MVP], May 18, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.