I am looking at Use WMI to Enumerate Local User Accounts
from http://www.microsoft.com/technet/treeview/default.asp?
url=/technet/ScriptCenter/user/ScrUG156.asp and I ran this
script on one of my Windows 2003 Active Directory. I am
receiving a blank results when run this program. Need help
to figure out why this script not working. Do I need to
change LocalAccount = False in order to work? Is there a
DomainAccount = True?
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer
& "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_UserAccount Where LocalAccount = True")
For Each objItem in colItems
Wscript.Echo "Account Type: " & objItem.AccountType
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Disabled: " & objItem.Disabled
Wscript.Echo "Domain: " & objItem.Domain
Wscript.Echo "Full Name: " & objItem.FullName
Wscript.Echo "Local Account: " & objItem.LocalAccount
Wscript.Echo "Lockout: " & objItem.Lockout
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Password Changeable: " &
objItem.PasswordChangeable
Wscript.Echo "Password Expires: " &
objItem.PasswordExpires
Wscript.Echo "Password Required: " &
objItem.PasswordRequired
Wscript.Echo "SID: " & objItem.SID
Wscript.Echo "SID Type: " & objItem.SIDType
Wscript.Echo "Status: " & objItem.Status
WScript.echo "mail: " & objItem.Mail
Wscript.Echo
Next
I just did a test script that work as follows
objItem.Caption will format like so - domain\name
objItem.name will format like so - name
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_UserAccount")
For Each objItem in colItems
Wscript.Echo "Account Type: " & objItem.AccountType
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo
Next
"B V" <bve...@hotmail.com> wrote in message
news:031301c3a94c$7af79380$a101...@phx.gbl...
Thank you and I will give that a try. I'll let you know
what the result will be. Thanks.
>.
>
AccountType: 512
Caption: Guest
Description: Built-in account for guest
Full Name: Guest, My
Email: gu...@mydomain.com
Any help will be appreciated. Can you explain how your
script work when import users_info.txt? I just wanted to
make sure users_info.txt contain the right format for the
script to run properly. Thank you.
>.
>
to read or create a text file you need to use the Script Runtime
There is an object called the FileSystemObjectHave a look here at how it
works
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjfilesystem.asp
once you have a file then you can use the WMI to file in the details you
want eg Caption: Guest
Can you explain what you are trying to do and I may be able to help further.
"B V" <bve...@hotmail.com> wrote in message
news:056001c3aa54$1f442400$a401...@phx.gbl...
Thank you for getting back to me. Very appreciated.
Apologize for the confusion. What I wanted is to create a
user according to the users_info.txt and if that user
already exist on my Domain, then it will update whatever
field it is missing, eg. Description field, Full Name,
Email, etc.
When I ran the script after you assisted me, the screen
displayed Caption and other things but I tried
objItem.Mail, it told me that this object is not
available, unless I am using the wrong Object type.
I hope I explain to you correctly.
Thank you
>.
>
Active directory services interfaces (ADSI) is a way to program/script items
that are held in your Active directory e.g. users
to get the email of a user in your AD you could do this
Set objUser = GetObject("LDAP://CN=John Smith,OU=Department,DC=domain,
DC=com")
strMail = objUser.Get("mail")
WScript.Echo strMail
you will need to read in user.txt (FileSystemObject) and then use ADSI to
create the users in your AD or fill in items such as email
have a look here for more on ADSI
hope this helps
"B V" <bve...@hotmail.com> wrote in message
news:423c01c3aad4$2d1056a0$a601...@phx.gbl...
Thank you for your assistant and the informations. I will
give that a try.
I had used a script for inputting Email from one of the
Newsgroup. Do you know how to fix the Email Field (since
no one has resolved his issue) that only display the email
address and not also display the username? For example, in
my user_info.txt, I have something like this.....
us...@mydomain.com, us...@yahoo.com
In the Email Field, it will display both as
us...@mydomain.com, us...@yahoo.com. How do I re-modify
the script where the Email Field will only display
us...@yahoo.com and not us...@mydomain.com?
Once again, thank you for your kindness.
>Option Explicit
>Dim objRootDSE, objTrans, objFSO, objFile, objUser
>Dim strDNSDomain, strNetBIOSDomain, strFileName
>Dim strEmail, strNTName, strUserDN
>
>' Specify the file of email addresses.
>strFileName = "c:\MyFolder\emails.txt"
>
>' Open the file.
>Set objFSO = CreateObject("Scripting.FileSystemObject")
>Set objFile = objFSO.OpenTextFile(strFileName, 1)
>
>' Determine DNS domain name from RootDSE object.
>Set objRootDSE = GetObject("LDAP://RootDSE")
>strDNSDomain = objRootDSE.Get("defaultNamingContext")
>
>' Use the NameTranslate object to find the NetBIOS domain
>name from the
>' DNS domain name.
>Set objTrans = CreateObject("NameTranslate")
>objTrans.Init 3, strDNSDomain
>objTrans.Set 1, strDNSDomain
>strNetBIOSDomain = objTrans.Get(3)
>' Remove trailing backslash.
>strNetBIOSDomain = Left(strNetBIOSDomain, Len
>(strNetBIOSDomain) - 1)
>
>' Use NameTranslate to convert NT names to Distinguished
>Names.
>objTrans.Init 1, strNetBIOSDomain
>
>' Read each line of the file.
>Do Until objFile.AtEndOfStream
> strEmail = Trim(objFile.ReadLine)
> If strEmail <> "" Then
> ' Extract the user NT name from the Email address.
> strNTName = Mid(strEmail, 1, InStr(strEmail, "@") - 1)
> ' Convert the NT name to the Distinguished Name.
> objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
> strUserDN = objTrans.Get(1)
> ' Bind to the user object.
> Set objUser = GetObject("LDAP://" & strUserDN)
> ' Assign the mail attribute.
> objUser.Put "mail", strEmail
> objUser.SetInfo
> End If
>Loop
>
>' Clean up.
>objFile.Close
>Wscript.Echo "Done"
the old loop does this
Do Until objFile.AtEndOfStream
> > strEmail = Trim(objFile.ReadLine)
> > If strEmail <> "" Then
> > ' Extract the user NT name from the Email address.
> > strNTName = Mid(strEmail, 1, InStr(strEmail, "@") - 1)
> > ' Convert the NT name to the Distinguished Name.
> > objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
> > strUserDN = objTrans.Get(1)
> > ' Bind to the user object.
> > Set objUser = GetObject("LDAP://" & strUserDN)
> > ' Assign the mail attribute.
> > objUser.Put "mail", strEmail
> > objUser.SetInfo
> > End If
> >Loop
strEmail will always = us...@mydomain.com, us...@yahoo.com as they are on
the same line and all strEmail holds is a line of text.
strNTName = Mid(strEmail, 1, InStr(strEmail, "@") - 1) will always try and
find the first @ and pull of the first part e.g.
if you line is us...@mydomain.com, us...@yahoo.com then strNTName will =
user1 (this is from us...@mydomain.com)
you need to change strEmail to get just one email address like so
strEmail = Mid(strEmail, 1, InStr(strEmail, ",") - 1)
us...@mydomain.com, us...@yahoo.com will become us...@mydomain.com
then you can do what you like to the new version of strEmail such as get
the part before the @ or just add it to you active directory with
objUser.Put "mail", strEmail
objUser.SetInfo
hope this helps
thanks
"B V" <bve...@hotmail.com> wrote in message
news:007901c3ad33$0daaa390$a401...@phx.gbl...
user1, te...@yahoo.com
In the Email field, it display user1, te...@yahoo.com.
Now, I guess I need to write another script to remove
user1 and keep te...@yahoo.com in the Email field. sorry I
did not explain to you correctly. Wonder if you know how
to write that script. If not, then I will figure it out
myself. Thank you for assisting me. Your suggestion help
me. Thank you so much.
>.
>