Home All Groups Group Topic Archive Search About


Author
13 Mar 2007 8:53 PM
james brady
I need a vb script that will scan all the computers in my domain and return
the sytem time. It would be nice to export the computer name and system time
directly to excel. A DOS script would also work.


HELP?!?!

Author
14 Mar 2007 6:16 AM
bg
On Mar 13, 3:53 pm, james brady <jamesbr***@discussions.microsoft.com>
wrote:
> I need a vb script that will scan all the computers in my domain and return
> the sytem time. It would be nice to export the computer name and system time
> directly to excel. A DOS script would also work.
>
> HELP?!?!

Try this...

Takes two args: <domain> and <output file>

You should be able to import the resultant (semicolon delimited) file
into Excel.  Not sure what the performance will be like on this since
I don't know the size of your domain.  Also the time returned is in 24
hour clock.  Hope this helps.


sDomain = Trim(WScript.Arguments(0)) 'domain to query
sLog = Trim(WScript.Arguments(1)) 'output file

Set oFso = CreateObject("Scripting.FileSystemObject")
Set oLog = oFso.CreateTextFile(sLog, True) 'create output file,
overwrite if exists
Set oDomain = GetObject("WinNT://" & sDomain)

iElement = 0
For Each oObject In oDomain
    If Trim(UCase(oObject.Class)) = "COMPUTER" Then
        ReDim Preserve aHosts(iElement)
        aHosts(iElement) = Trim(UCase(oObject.Name))
        iElement = iElement + 1
    End If
Next

iIndex = 0
For iLine = LBound(aHosts) To UBound(aHosts)
    sHost = Trim(aHosts(iLine))
    Set oWmi = GetObject("winmgmts:\\" & sHost & "\root\cimv2")
    Set colDateTime = oWmi.ExecQuery("SELECT Hour, Minute, Second FROM
Win32_LocalTime")

    For Each oDateTime in colDateTime
        ReDim Preserve aResults(iIndex)
        sHour = Trim(oDateTime.Hour)
        If sHour < 10 And Len(sHour) = 1 Then
            sHour = "0" & sHour
        End If
        sMin = Trim(oDateTime.Minute)
        If sMin < 10 And Len(sMin) = 1 Then
            sMin = "0" & sMin
        End If
        sSec = Trim(oDateTime.Second)
        If sSec < 10 And Len(sSec) = 1 Then
            sSec = "0" & sMin
        End If
        aResults(iIndex) = sHost & "-" & sHour & ":" & sMin & ":" &
sSec
        iIndex = iIndex + 1
    Next
Next

oLog.WriteLine(Join(aResults, ";"))
oLog.Close()

Set oFso = Nothing
Set oList = Nothing
Set oLog = Nothing
Set oDomain = Nothing
Set oObject = Nothing
Set oWmi = Nothing
Set oDateTime = Nothing
Author
14 Mar 2007 2:20 PM
james brady
This is awesome. I am new to scripting, can you tell me how it works?

d'oh! getting lots of errors when i try to run the script.



Show quote
"bg" wrote:

> On Mar 13, 3:53 pm, james brady <jamesbr***@discussions.microsoft.com>
> wrote:
> > I need a vb script that will scan all the computers in my domain and return
> > the sytem time. It would be nice to export the computer name and system time
> > directly to excel. A DOS script would also work.
> >
> > HELP?!?!
>
> Try this...
>
> Takes two args: <domain> and <output file>
>
> You should be able to import the resultant (semicolon delimited) file
> into Excel.  Not sure what the performance will be like on this since
> I don't know the size of your domain.  Also the time returned is in 24
> hour clock.  Hope this helps.
>
>
> sDomain = Trim(WScript.Arguments(0)) 'domain to query
> sLog = Trim(WScript.Arguments(1)) 'output file
>
> Set oFso = CreateObject("Scripting.FileSystemObject")
> Set oLog = oFso.CreateTextFile(sLog, True) 'create output file,
> overwrite if exists
> Set oDomain = GetObject("WinNT://" & sDomain)
>
> iElement = 0
> For Each oObject In oDomain
>     If Trim(UCase(oObject.Class)) = "COMPUTER" Then
>         ReDim Preserve aHosts(iElement)
>         aHosts(iElement) = Trim(UCase(oObject.Name))
>         iElement = iElement + 1
>     End If
> Next
>
> iIndex = 0
> For iLine = LBound(aHosts) To UBound(aHosts)
>     sHost = Trim(aHosts(iLine))
>     Set oWmi = GetObject("winmgmts:\\" & sHost & "\root\cimv2")
>     Set colDateTime = oWmi.ExecQuery("SELECT Hour, Minute, Second FROM
> Win32_LocalTime")
>
>     For Each oDateTime in colDateTime
>         ReDim Preserve aResults(iIndex)
>         sHour = Trim(oDateTime.Hour)
>         If sHour < 10 And Len(sHour) = 1 Then
>             sHour = "0" & sHour
>         End If
>         sMin = Trim(oDateTime.Minute)
>         If sMin < 10 And Len(sMin) = 1 Then
>             sMin = "0" & sMin
>         End If
>         sSec = Trim(oDateTime.Second)
>         If sSec < 10 And Len(sSec) = 1 Then
>             sSec = "0" & sMin
>         End If
>         aResults(iIndex) = sHost & "-" & sHour & ":" & sMin & ":" &
> sSec
>         iIndex = iIndex + 1
>     Next
> Next
>
> oLog.WriteLine(Join(aResults, ";"))
> oLog.Close()
>
> Set oFso = Nothing
> Set oList = Nothing
> Set oLog = Nothing
> Set oDomain = Nothing
> Set oObject = Nothing
> Set oWmi = Nothing
> Set oDateTime = Nothing
>
>
Author
19 Mar 2007 4:24 AM
bg
On Mar 14, 9:20 am, james brady <jamesbr***@discussions.microsoft.com>
wrote:
Show quote
> This is awesome. I am new to scripting, can you tell me how it works?
>
> d'oh! getting lots of errors when i try to run the script.
>
>
>
> "bg" wrote:
> > On Mar 13, 3:53 pm, james brady <jamesbr***@discussions.microsoft.com>
> > wrote:
> > > I need a vb script that will scan all the computers in my domain and return
> > > the sytem time. It would be nice to export the computer name and system time
> > > directly to excel. A DOS script would also work.
>
> > > HELP?!?!
>
> > Try this...
>
> > Takes two args: <domain> and <output file>
>
> > You should be able to import the resultant (semicolon delimited) file
> > into Excel.  Not sure what the performance will be like on this since
> > I don't know the size of your domain.  Also the time returned is in 24
> > hour clock.  Hope this helps.
>
> > sDomain = Trim(WScript.Arguments(0)) 'domain to query
> > sLog = Trim(WScript.Arguments(1)) 'output file
>
> > Set oFso = CreateObject("Scripting.FileSystemObject")
> > Set oLog = oFso.CreateTextFile(sLog, True) 'create output file,
> > overwrite if exists
> > Set oDomain = GetObject("WinNT://" & sDomain)
>
> > iElement = 0
> > For Each oObject In oDomain
> >     If Trim(UCase(oObject.Class)) = "COMPUTER" Then
> >         ReDim Preserve aHosts(iElement)
> >         aHosts(iElement) = Trim(UCase(oObject.Name))
> >         iElement = iElement + 1
> >     End If
> > Next
>
> > iIndex = 0
> > For iLine = LBound(aHosts) To UBound(aHosts)
> >     sHost = Trim(aHosts(iLine))
> >     Set oWmi = GetObject("winmgmts:\\" & sHost & "\root\cimv2")
> >     Set colDateTime = oWmi.ExecQuery("SELECT Hour, Minute, Second FROM
> > Win32_LocalTime")
>
> >     For Each oDateTime in colDateTime
> >         ReDim Preserve aResults(iIndex)
> >         sHour = Trim(oDateTime.Hour)
> >         If sHour < 10 And Len(sHour) = 1 Then
> >             sHour = "0" & sHour
> >         End If
> >         sMin = Trim(oDateTime.Minute)
> >         If sMin < 10 And Len(sMin) = 1 Then
> >             sMin = "0" & sMin
> >         End If
> >         sSec = Trim(oDateTime.Second)
> >         If sSec < 10 And Len(sSec) = 1 Then
> >             sSec = "0" & sMin
> >         End If
> >         aResults(iIndex) = sHost & "-" & sHour & ":" & sMin & ":" &
> > sSec
> >         iIndex = iIndex + 1
> >     Next
> > Next
>
> > oLog.WriteLine(Join(aResults, ";"))
> > oLog.Close()
>
> > Set oFso = Nothing
> > Set oList = Nothing
> > Set oLog = Nothing
> > Set oDomain = Nothing
> > Set oObject = Nothing
> > Set oWmi = Nothing
> > Set oDateTime = Nothing- Hide quoted text -
>
> - Show quoted text -

what are the errors that you are getting?  this ran fine in my
environment.
Author
19 Mar 2007 11:08 PM
james brady
Line: 1

Char: 1

Error: Subscript out of range

Code: 800A0009








Show quote
"bg" wrote:

> On Mar 14, 9:20 am, james brady <jamesbr***@discussions.microsoft.com>
> wrote:
> > This is awesome. I am new to scripting, can you tell me how it works?
> >
> > d'oh! getting lots of errors when i try to run the script.
> >
> >
> >
> > "bg" wrote:
> > > On Mar 13, 3:53 pm, james brady <jamesbr***@discussions.microsoft.com>
> > > wrote:
> > > > I need a vb script that will scan all the computers in my domain and return
> > > > the sytem time. It would be nice to export the computer name and system time
> > > > directly to excel. A DOS script would also work.
> >
> > > > HELP?!?!
> >
> > > Try this...
> >
> > > Takes two args: <domain> and <output file>
> >
> > > You should be able to import the resultant (semicolon delimited) file
> > > into Excel.  Not sure what the performance will be like on this since
> > > I don't know the size of your domain.  Also the time returned is in 24
> > > hour clock.  Hope this helps.
> >
> > > sDomain = Trim(WScript.Arguments(0)) 'domain to query
> > > sLog = Trim(WScript.Arguments(1)) 'output file
> >
> > > Set oFso = CreateObject("Scripting.FileSystemObject")
> > > Set oLog = oFso.CreateTextFile(sLog, True) 'create output file,
> > > overwrite if exists
> > > Set oDomain = GetObject("WinNT://" & sDomain)
> >
> > > iElement = 0
> > > For Each oObject In oDomain
> > >     If Trim(UCase(oObject.Class)) = "COMPUTER" Then
> > >         ReDim Preserve aHosts(iElement)
> > >         aHosts(iElement) = Trim(UCase(oObject.Name))
> > >         iElement = iElement + 1
> > >     End If
> > > Next
> >
> > > iIndex = 0
> > > For iLine = LBound(aHosts) To UBound(aHosts)
> > >     sHost = Trim(aHosts(iLine))
> > >     Set oWmi = GetObject("winmgmts:\\" & sHost & "\root\cimv2")
> > >     Set colDateTime = oWmi.ExecQuery("SELECT Hour, Minute, Second FROM
> > > Win32_LocalTime")
> >
> > >     For Each oDateTime in colDateTime
> > >         ReDim Preserve aResults(iIndex)
> > >         sHour = Trim(oDateTime.Hour)
> > >         If sHour < 10 And Len(sHour) = 1 Then
> > >             sHour = "0" & sHour
> > >         End If
> > >         sMin = Trim(oDateTime.Minute)
> > >         If sMin < 10 And Len(sMin) = 1 Then
> > >             sMin = "0" & sMin
> > >         End If
> > >         sSec = Trim(oDateTime.Second)
> > >         If sSec < 10 And Len(sSec) = 1 Then
> > >             sSec = "0" & sMin
> > >         End If
> > >         aResults(iIndex) = sHost & "-" & sHour & ":" & sMin & ":" &
> > > sSec
> > >         iIndex = iIndex + 1
> > >     Next
> > > Next
> >
> > > oLog.WriteLine(Join(aResults, ";"))
> > > oLog.Close()
> >
> > > Set oFso = Nothing
> > > Set oList = Nothing
> > > Set oLog = Nothing
> > > Set oDomain = Nothing
> > > Set oObject = Nothing
> > > Set oWmi = Nothing
> > > Set oDateTime = Nothing- Hide quoted text -
> >
> > - Show quoted text -
>
> what are the errors that you are getting?  this ran fine in my
> environment.
>
>
Author
28 Mar 2007 2:04 AM
james brady
still cant get it to work!

Show quote
"james brady" wrote:

> Line: 1
>
> Char: 1
>
> Error: Subscript out of range
>
> Code: 800A0009
>
>
>
>
>
>
>
>
> "bg" wrote:
>
> > On Mar 14, 9:20 am, james brady <jamesbr***@discussions.microsoft.com>
> > wrote:
> > > This is awesome. I am new to scripting, can you tell me how it works?
> > >
> > > d'oh! getting lots of errors when i try to run the script.
> > >
> > >
> > >
> > > "bg" wrote:
> > > > On Mar 13, 3:53 pm, james brady <jamesbr***@discussions.microsoft.com>
> > > > wrote:
> > > > > I need a vb script that will scan all the computers in my domain and return
> > > > > the sytem time. It would be nice to export the computer name and system time
> > > > > directly to excel. A DOS script would also work.
> > >
> > > > > HELP?!?!
> > >
> > > > Try this...
> > >
> > > > Takes two args: <domain> and <output file>
> > >
> > > > You should be able to import the resultant (semicolon delimited) file
> > > > into Excel.  Not sure what the performance will be like on this since
> > > > I don't know the size of your domain.  Also the time returned is in 24
> > > > hour clock.  Hope this helps.
> > >
> > > > sDomain = Trim(WScript.Arguments(0)) 'domain to query
> > > > sLog = Trim(WScript.Arguments(1)) 'output file
> > >
> > > > Set oFso = CreateObject("Scripting.FileSystemObject")
> > > > Set oLog = oFso.CreateTextFile(sLog, True) 'create output file,
> > > > overwrite if exists
> > > > Set oDomain = GetObject("WinNT://" & sDomain)
> > >
> > > > iElement = 0
> > > > For Each oObject In oDomain
> > > >     If Trim(UCase(oObject.Class)) = "COMPUTER" Then
> > > >         ReDim Preserve aHosts(iElement)
> > > >         aHosts(iElement) = Trim(UCase(oObject.Name))
> > > >         iElement = iElement + 1
> > > >     End If
> > > > Next
> > >
> > > > iIndex = 0
> > > > For iLine = LBound(aHosts) To UBound(aHosts)
> > > >     sHost = Trim(aHosts(iLine))
> > > >     Set oWmi = GetObject("winmgmts:\\" & sHost & "\root\cimv2")
> > > >     Set colDateTime = oWmi.ExecQuery("SELECT Hour, Minute, Second FROM
> > > > Win32_LocalTime")
> > >
> > > >     For Each oDateTime in colDateTime
> > > >         ReDim Preserve aResults(iIndex)
> > > >         sHour = Trim(oDateTime.Hour)
> > > >         If sHour < 10 And Len(sHour) = 1 Then
> > > >             sHour = "0" & sHour
> > > >         End If
> > > >         sMin = Trim(oDateTime.Minute)
> > > >         If sMin < 10 And Len(sMin) = 1 Then
> > > >             sMin = "0" & sMin
> > > >         End If
> > > >         sSec = Trim(oDateTime.Second)
> > > >         If sSec < 10 And Len(sSec) = 1 Then
> > > >             sSec = "0" & sMin
> > > >         End If
> > > >         aResults(iIndex) = sHost & "-" & sHour & ":" & sMin & ":" &
> > > > sSec
> > > >         iIndex = iIndex + 1
> > > >     Next
> > > > Next
> > >
> > > > oLog.WriteLine(Join(aResults, ";"))
> > > > oLog.Close()
> > >
> > > > Set oFso = Nothing
> > > > Set oList = Nothing
> > > > Set oLog = Nothing
> > > > Set oDomain = Nothing
> > > > Set oObject = Nothing
> > > > Set oWmi = Nothing
> > > > Set oDateTime = Nothing- Hide quoted text -
> > >
> > > - Show quoted text -
> >
> > what are the errors that you are getting?  this ran fine in my
> > environment.
> >
> >

AddThis Social Bookmark Button