|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Need VbScript
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?!?! 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 Try this...> 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?!?! 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 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 > > 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? what are the errors that you are getting? this ran fine in my> > 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 - environment. 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. > > 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. > > > > |
|||||||||||||||||||||||