how can I get the output of below script in txt and csv format and where i need to add the switch ?
-
Tuesday, March 20, 2012 7:26 AM
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
dtmExpirationDate = "04/20/2012"
Set objShell = CreateObject("Wscript.Shell")
lngTimeZoneBias = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngTimeZoneBias)) = "LONG" Then
lngFinalBias = lngTimeZoneBias
ElseIf UCase(TypeName(lngTimeZoneBias)) = "VARIANT()" Then
lngFinalBias = 0
For k = 0 To UBound(lngTimeZoneBias)
lngFinalBias = lngFinalBias + (lngTimeZoneBias(k) * 256^k)
Next
End IfdtmNewDate = DateAdd("n", lngFinalBias, dtmExpirationDate)
lngSeconds = DateDiff("s", #1/1/1601#, dtmNewDate)
strModifiedExpirationDate = CStr(lngSeconds) & "0000000"Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnectionobjCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREEobjCommand.CommandText = _
"SELECT Name FROM 'LDAP://DC=a,DC=b,DC=org' WHERE objectClass='user' " & _
"AND accountExpires<='" & strModifiedExpirationDate & "'"
Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop
All Replies
-
Tuesday, March 20, 2012 7:42 AM
Place this on the third line of your script:
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objLogFile = objFSO.CreateTextFile("logfile.log", 8, True)
Place this after wscript.echo in the last loop:
objlogfile.writeline objrecordsset.fields("name").valuePlace this at the end of your script:
objlogfile.Close
This will output your file to logfile.log. Is that what you are looking for? Also if you want to output your current script to a text file you could just run it as such:
cscript yourscript.vbs > logfile.log
- Proposed As Answer by Richard MuellerMVP, Moderator Friday, March 23, 2012 5:17 PM
- Marked As Answer by IamMredMicrosoft Employee, Owner Sunday, March 25, 2012 5:15 AM
-
Tuesday, March 20, 2012 7:57 AM
Hi.. I have made the entry as below but getting error "
---------------------------
Windows Script Host
---------------------------
Script: C:\Documents and Settings\s0092517\Desktop\accountexpiry.vbs
Line: 41
Char: 39
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error---------------------------
OK
---------------------------
"
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
dtmExpirationDate = "04/20/2012"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.CreateTextFile("logfile.log", 8, True)Set objShell = CreateObject("Wscript.Shell")
lngTimeZoneBias = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngTimeZoneBias)) = "LONG" Then
lngFinalBias = lngTimeZoneBias
ElseIf UCase(TypeName(lngTimeZoneBias)) = "VARIANT()" Then
lngFinalBias = 0
For k = 0 To UBound(lngTimeZoneBias)
lngFinalBias = lngFinalBias + (lngTimeZoneBias(k) * 256^k)
Next
End IfdtmNewDate = DateAdd("n", lngFinalBias, dtmExpirationDate)
lngSeconds = DateDiff("s", #1/1/1601#, dtmNewDate)
strModifiedExpirationDate = CStr(lngSeconds) & "0000000"Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnectionobjCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREEobjCommand.CommandText = _
"SELECT Name FROM 'LDAP://DC=a,DC=b,DC=org' WHERE objectClass='user' " & _
"AND accountExpires<='" & strModifiedExpirationDate & "'"
Set objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objlogfile.writeline objrecordsset.fields("name").value
objRecordSet.MoveNext
Loop objlogfile.Close- Edited by Gautam Ji Tuesday, March 20, 2012 7:59 AM
-
Tuesday, March 20, 2012 8:36 AMremove the wscript.echo, what I meant was place it on the line after wscript.echo. I was not very clear sorry. The same for the last line, objlogfile.close should be on a new line. Can you try that?
-
Tuesday, March 20, 2012 10:28 AM
Hi..... After following your words. it working fine and giving outpu of logfile.log on desktop but in logfile.log is not containg any users account expiry information..
-
Tuesday, March 20, 2012 11:34 AM
That could have any number of reason, in the script you posted you query the following location: 'LDAP://DC=a,DC=b,DC=org' i assume you query your actual domain in the real script you are running. If you have a typo there your script will have no results. Did you actually get results when you were running the command with wscript.echo?
-
Tuesday, March 20, 2012 11:55 AM
When i m running script on comman prompt, it is displaying all the users account list..
-
Tuesday, March 20, 2012 2:22 PM
Alright then, what do you get when you run the original script you posted as such:
cscript yourscript.vbs >> logfile.log
-
Tuesday, March 20, 2012 2:35 PM
List of all user account expiry dates...........
But there is some doubt that some users were checked and now they are mark for never expire account..........
so with this script showing all those users details whose account were exipred but now set for Never...............
-
Tuesday, March 20, 2012 3:16 PMModerator
Hi,
My advice is to start learning and try to start writing some of the code yourself. Otherwise, this thread will go on forever. Don't be the person who doesn't understand why something works and just wants to know the magic phrase you need to type. Be the person who can understand the code and adjust it for your own needs. In this way you will grow in your own understanding of what is happening and you will also be able to help others.
Bill
-
Wednesday, March 21, 2012 9:21 AM
Thanks..............
I'll try..............

