[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

VBS script InstallDate

Hi!
Is it possible to link a txt document to a vbs script?  I have 200 computers and I want to know the Install Date of the OS.  I have to modify the script for each computer...

strComputer = "ba01infodev"
 Set dtmInstallDate = CreateObject( _
  "WbemScripting.SWbemDateTime")
 Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" _
   & strComputer & "\root\cimv2")
 Set colOperatingSystems = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")
 For Each objOperatingSystem in colOperatingSystems
   MsgBox "Install Date: " & getmydat (objOperatingSystem.InstallDate)
 Next

Function getmydat(wmitime)
   dtmInstallDate.Value = wmitime
   getmydat = dtmInstallDate.GetVarDate
 End function

Thanks!

JS
0
polycorjsp
Asked:
polycorjsp
1 Solution
 
RobSampsonCommented:
Hi, this script will do that for you.  It reads a text file called computers.txt and outputs the data to output.csv

Regards,

Rob.

strComputers = "computers.txt"
strOutput = "output.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1

Set objInput = objFSO.OpenTextFile(strComputers, ForReading, False)
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """Computer"",""InstallDate"""

While Not objInput.AtEndOfStream
	strComputer = Trim(objInput.ReadLine)
	If strComputer <> "" Then
		If Ping(strComputer) = True Then
			Set dtmInstallDate = CreateObject("WbemScripting.SWbemDateTime")
			On Error Resume Next
			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
			If Err.Number = 0 Then
				Err.Clear
				On Error GoTo 0
				Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
				For Each objOperatingSystem in colOperatingSystems
					objOutput.WriteLine """" & strComputer & """,""" & getmydat (objOperatingSystem.InstallDate) & """"
				Next
			Else
				objOutput.WriteLine """" & strComputer & """,""ERROR " & Err.Number & ": " & Err.Description & """"
				Err.Clear
				On Error GoTo 0
			End If
		Else
			objOutput.WriteLine """" & strComputer & """,""OFFLINE"""
		End If
	End If
Wend
WScript.Echo "Done. Please see " & strOutput

Function getmydat(wmitime)
   dtmInstallDate.Value = wmitime
   getmydat = dtmInstallDate.GetVarDate
End Function

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
Bill PrewCommented:
This should get you pretty close, let me know if you have any questions.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

sInfile = "c:\temp\list.txt"

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Open input file
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)

' Read each line of the file and process it
Do While Not oInfile.AtEndOfStream
   strComputer = oInfile.ReadLine
   Set dtmInstallDate = CreateObject( _
      "WbemScripting.SWbemDateTime")
   Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _
      & strComputer & "\root\cimv2")
   Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")
   For Each objOperatingSystem in colOperatingSystems
      MsgBox "Install Date: " & getmydat (objOperatingSystem.InstallDate)
   Next
Loop

' Cleanup and end
oInfile.Close
Set oInfile = Nothing
Set oFSO = Nothing
Wscript.Quit

Function getmydat(wmitime)
   dtmInstallDate.Value = wmitime
   getmydat = dtmInstallDate.GetVarDate
 End function

Open in new window

~bp
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now