Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

net user * vbscript

759 views
Skip to first unread message

AaronK

unread,
Jan 23, 2008, 8:32:43 AM1/23/08
to
I am looking for a method to return properties for all the user accounts on
a local machine, similar to the "net user username". I have found a script
that will return all the users and some properties but not the ones I am
particularly looking for such as "password last set" and "last logon".
Example of the information I am trying to get for all users on the local
machine. Any help would be great.

User name Administrator
Full Name
Comment Built-in account for administering the
computer/domain
User's comment
Country code 000 (System Default)
Account active Yes
Account expires Never

Password last set 12/6/2007 9:27 AM
Password expires Never
Password changeable 12/6/2007 9:27 AM
Password required Yes
User may change password Yes

Workstations allowed All
Logon script
User profile
Home directory
Last logon 12/5/2007 9:13 AM

Logon hours allowed All

Thanks,

Aaron K


Jeffery Hicks [MVP]

unread,
Jan 23, 2008, 8:52:39 AM1/23/08
to
Here's a scheme browsing script I've used in the past. When prompted, enter
the ADSIpath for an object like WinNT://Computer01/Administrator,user


On Error Resume Next
Dim objNetwork
Set objNetwork=CreateObject("WScript.Network")
strTitle="ADSI Schema Browse"
strPrompt="Enter an ADSI path:"
strDefault="WinNT://" & objNetwork.ComputerName
strADSPath=InputBox(strPrompt,strTitle,strDefault)
If strADSPath="" Then WScript.Quit

Set objVar=GetObject(strADSPath)
If IsObject(objVar) Then
strHeader="General Object properties for " & objVar.Name

wscript.echo strHeader
WScript.Echo String(Len(strHeader),"-")

Set objClass = GetObject(objVar.Schema)
Wscript.Echo "Class: " & objClass.Name
Wscript.Echo "GUID: " & objClass.GUID
Wscript.Echo "Implemented by: " & objClass.CLSID

WScript.Echo VbCrLf

strMandatoryHeader="Mandatory Properties in this Class (" &_
UBound(objClass.MandatoryProperties)+1 & "): "
Wscript.Echo strMandatoryHeader
WScript.Echo String(Len(strMandatoryHeader),"-")
For Each objProperty In objClass.MandatoryProperties
Wscript.Echo " " & objProperty & " : " &_
GetValue(objVar,objProperty)
Next

WScript.Echo VbCrLf

strOptionalHeader="Optional Properties in this Class (" &_
UBound(objClass.OptionalProperties)+1 & "): "
Wscript.Echo strOptionalHeader
WScript.Echo String(Len(strOptionalHeader),"-")

For Each objProperty In objClass.OptionalProperties
Wscript.Echo " " & objProperty & " : " &_
GetValue(objVar,objProperty)
Next
Else
WScript.Echo "Failed to get " & strADSPath
End if

wscript.quit

Function GetValue(objItem,strProperty)
On Error Resume Next
Dim objProperty
objProperty=objItem.Get(strProperty)
If TypeName(objProperty)<>"Empty" Then
If IsArray(objProperty) Then
if TypeName(objProperty)="Byte()" Then
strProp="Byte array"
Else
wscript.echo "!!" & strProperty & " is an array!!"
For x=0 To UBound(objProperty)-1
strProp=strProp & " " &objProperty(x) & VbCrLf
Next
End If
Else
strProp=objItem.Get(strProperty)
If strProp="" Then strProp="Defined but no value"
End If
Else
strProp="Not Defined"
End If
GetValue=strProp

End Function

--
Jeffery Hicks MCSE, MCSA, MCT
Microsoft PowerShell MVP
http://www.scriptinganswers.com
http://www.powershellcommunity.org
http://jdhitsolutions.blogspot.com

Now Available: WSH and VBScript Core: TFM
Now Available: Windows PowerShell v1.0: TFM 2nd Ed.


"AaronK" <aar...@fake-email.com> wrote in message
news:uo9YvRcX...@TK2MSFTNGP06.phx.gbl...

Richard Mueller [MVP]

unread,
Jan 23, 2008, 10:44:43 AM1/23/08
to

"AaronK" <aar...@fake-email.com> wrote in message
news:uo9YvRcX...@TK2MSFTNGP06.phx.gbl...

The code Jeffrey posted should reveal all of the attributes available for
local user objects. It should include:

passwordAge (in seconds)
passwordExpired (time when password expired)
lastLogin (when user last logged in)
minPasswordAge

You would need to calculate when the password was last set and when it
expires. A VBScript program do dump out all local user accounts on a
computer could be similar to:
=====
' Bind to computer object.
Set objComputer = GetObject("WinNT://MyComputer")
' Filter on user objects.
objComputer.Filter = Array("user")
' Enumerate all user objects.
For Each objUser In objComputer
On Error Resume Next
dtmLast = objUser.lastLogin
If (Err.Number <> 0) Then
dtmLast = "Never"
End If
On Error GoTo 0
Wscript.Echo objUser.Name _
& ", " & objUser.passwordAge _
& ", " & dtmLast
Next
===========
I trapped the possible error if lastLogin has no value so the script does
not stop.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


Aaron Klink

unread,
Jan 23, 2008, 3:34:18 PM1/23/08
to
Thank you both.

Great scripts

Aaron

"Richard Mueller [MVP]" <rlmuelle...@ameritech.nospam.net> wrote in
message news:eB2mibdX...@TK2MSFTNGP06.phx.gbl...

0 new messages