none
how can I get the output of below script in txt and csv format and where i need to add the switch ?

    Question

  • 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 If

    dtmNewDate = 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 = objConnection

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

    objCommand.CommandText = _
        "SELECT Name FROM 'LDAP://DC=a,DC=b,DC=org' WHERE objectClass='user' "  & _
            "AND accountExpires<='" & strModifiedExpirationDate & "'"
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst
    Do Until objRecordSet.EOF
        Wscript.Echo objRecordSet.Fields("Name").Value
        objRecordSet.MoveNext
    Loop

    Tuesday, March 20, 2012 7:26 AM

Answers

  • 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").value

    Place 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

    Tuesday, March 20, 2012 7:42 AM
    Moderator

All replies

  • 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").value

    Place 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

    Tuesday, March 20, 2012 7:42 AM
    Moderator
  • 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 If

    dtmNewDate = 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 = objConnection

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

    objCommand.CommandText = _
        "SELECT Name FROM 'LDAP://DC=a,DC=b,DC=org' WHERE objectClass='user' "  & _
            "AND accountExpires<='" & strModifiedExpirationDate & "'"
    Set objRecordSet = objCommand.Execute

    objRecordSet.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 7:57 AM
  • remove 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 8:36 AM
    Moderator
  • 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 10:28 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:34 AM
    Moderator
  • When i m running script on comman prompt, it is displaying all the users account list..

    Tuesday, March 20, 2012 11:55 AM
  • 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:22 PM
    Moderator
  • 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 2:35 PM
  • 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

    Tuesday, March 20, 2012 3:16 PM
    Moderator
  • Thanks..............

    I'll try..............

    Wednesday, March 21, 2012 9:21 AM