How Can I Get the Full Name and Description For My Local User Accounts?


Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I get the full name and description for each of my local user accounts?

— EB

SpacerHey, Scripting Guy! AnswerTechNet Script Center

Hey, EB. You know, this might be hard to believe, but many people view the Scripting Guys with suspicion. OK, good point; the part that is hard to believe is why they view the Scripting Guys with suspicion. As it turns out, many people look at the scripts in this column, and the scripts scattered throughout the Script Center, and think, “Those are too easy; there’s no way scripting can be that easy. These guys must be hiding something, they must be keeping all the good stuff for themselves.” It’s the Priory of Scion all over again!

Note. Of course, you might want to check here for opposing viewpoints, at least when it comes to the Priory of Scion.

The truth is, the Scripting Guys have no top-secret scripting knowledge. (Or, if we do, then we’ve somehow managed to keep this knowledge secret even from ourselves.) However, we understand why people sometimes feel this way. After all, scripting has a reputation as being really hard; there are plenty of people here at Microsoft who say things like, “Nobody writes scripts; nobody can write scripts.” When we Scripting Guys turn around and provide an easy solution to a problem, many people think, “Oh, sure, that was easy. A little too easy.”

So why are we rambling on like this? Well, EB wanted to know how to get the full name and description for all the local user accounts on a computer. We’ll tell everyone how to do that, but we felt we should warn you in advance: as you’re about to see, the solution is incredibly easy. We hope that that will be OK with you.

Here’s the script:

strComputer = “atl-fs-01”

Set colAccounts = GetObject(“WinNT://” & strComputer & “”) colAccounts.Filter = Array(“user”)

For Each objUser In colAccounts Wscript.Echo objUser.Name Wscript.Echo objUser.FullName Wscript.Echo Description Wscript.Echo Next

We warned you that this was going to be easy. As you can see, we assign the name of the computer in question (in this case, atl-fs-01) to a variable named strComputer. We then use the WinNT provider and the following line of code to bind to the System Account Manager (SAM) on that machine:

Set colAccounts = GetObject(“WinNT://” & strComputer & “”)

As you probably know, you can use the WinNT provider to do more than just get information about local user accounts: the WinNT provider can also retrieve information about local group accounts, installed services, installed printers, etc. Because we care about only user accounts, we next create a Filter that, well, filters the returned data, allowing only user account information to come back:

colAccounts.Filter = Array(“user”)

And sure, we can filter for other things. Want information about local groups, and only local groups? Here you go:

colAccounts.Filter = Array(“group”)

Here’s a variation that returns information about both users and groups (but nothing else):

colAccounts.Filter = Array(“user”, “group”)


Incidentally, we tried to find a way to make filtering harder, but we couldn’t. We guess that some things in life really are easy. (The only remotely tricky part here? Making sure you put everything into an array, even if you’re filtering for only one type of object.)

All that’s left now is to set up a For Each loop that loops through the collection of user accounts. For each account in the collection we echo back the values of the Name, FullName, and Description attributes:

For Each objUser In colAccounts
    Wscript.Echo objUser.Name 
    Wscript.Echo objUser.FullName 
    Wscript.Echo Description 

If you set aside your entire day assuming it would take you several hours to figure out how this script works, well, the Scripting Guys apologize for any inconvenience the simplicity of this code might have caused. Hopefully you’ll be able to find something to fill all that spare time.

Oh, wait: we know something that’s bound to be hard. If you’re anything like the Scripting Guys then there’s a good chance that many of your local accounts have never been assigned full names or descriptions. That’s the answer right there; after all, writing a script to modify the values of local user account properties has to be hard, right?

Never mind; that was easy, too:

strComputer = “atl-fs-01”

Set objUser = GetObject(“WinNT://” & strComputer & “/Test”)

objUser.FullName = “Test User Account” objUser.Description = “This account should used for test purposes only.” objUser.SetInfo

Turns out that all we need to do here is bind directly to the user account we want to modify; in this case, that’s an account named Test on the computer atl-fs-01. We then assign values to the FullName and Description attributes:

objUser.FullName = “Test User Account”
objUser.Description = “This account should used for test purposes only.”

And then, to actually save those changes, we call the SetInfo method:


And that’s it. All in all, this script might have been even easier than the first script we showed you. Dang!

Oh, well; we give up. We’re sorry, everyone, but it looks like scripting is nowhere near as hard as it’s cracked up to be. (We tried our best to make it difficult, but we couldn’t do it.) Apparently that’s something we’ll all just have to learn to live with.


Discussion is closed.

Feedback usabilla icon