EDN Admin
Well-known member
Hi All,
Im trying to write a script which will parse a text file listing AD usernames and output the expiry times of the accounts. The problem is the accountExpires attribute never returns a value, yet if I use "net user {name} /domain" I can see there is an expiry
date. Script is below if anyone can offer any clues:
<pre class="prettyprint lang-vb Define some variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
CONST ForReading = 1
CONST ForWriting = 1
InFile = "C:Scriptsin.txt"
OutFile = "C:Scriptsout.txt"
Configure input file
if not objFSO.FileExists(InFile) then
msgbox "Couldnt find the input file " & InFile
wscript.quit
end if
prepare the input file
strData = objFSO.OpenTextFile(InFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)
set up connection to active directory
Const ADS_SCOPE_SUBTREE = 2
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
on error resume next
parse the text file
For Each strLine in arrLines
objCommand.CommandText = "SELECT distinguishedName FROM LDAP://" & strDomain & " WHERE objectCategory=user AND samAccountName = " & strLine & ""
Set objRecordSet = objCommand.Execute
If Not objRecordSet.EOF Then
strDN = objRecordSet.Fields("distinguishedName").Value
set objUser = getObject(strDN)
ExpiryDate = objUser.AccountExpires
msgbox "Account: " & strLine & vbcrlf & "objUser: " & strDN & vbcrlf & "Expiry: " & ExpiryDate
End If
Next [/code]
<br/>
Thanks<br/>
Ben
<br/>
View the full article
Im trying to write a script which will parse a text file listing AD usernames and output the expiry times of the accounts. The problem is the accountExpires attribute never returns a value, yet if I use "net user {name} /domain" I can see there is an expiry
date. Script is below if anyone can offer any clues:
<pre class="prettyprint lang-vb Define some variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
CONST ForReading = 1
CONST ForWriting = 1
InFile = "C:Scriptsin.txt"
OutFile = "C:Scriptsout.txt"
Configure input file
if not objFSO.FileExists(InFile) then
msgbox "Couldnt find the input file " & InFile
wscript.quit
end if
prepare the input file
strData = objFSO.OpenTextFile(InFile,ForReading).ReadAll
arrLines = Split(strData,vbCrLf)
set up connection to active directory
Const ADS_SCOPE_SUBTREE = 2
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
on error resume next
parse the text file
For Each strLine in arrLines
objCommand.CommandText = "SELECT distinguishedName FROM LDAP://" & strDomain & " WHERE objectCategory=user AND samAccountName = " & strLine & ""
Set objRecordSet = objCommand.Execute
If Not objRecordSet.EOF Then
strDN = objRecordSet.Fields("distinguishedName").Value
set objUser = getObject(strDN)
ExpiryDate = objUser.AccountExpires
msgbox "Account: " & strLine & vbcrlf & "objUser: " & strDN & vbcrlf & "Expiry: " & ExpiryDate
End If
Next [/code]
<br/>
Thanks<br/>
Ben
<br/>
View the full article