Moordoom
asked on
Making a vbscript Wscript write to file instead of Echo
I have a vbscript I would like to run in a GPO start up for Asset Management. I currently have it written to pull all the information I want, but in ECHO only.
I would like it to write to a text file or CSV instead, and to overwrite the file each time the computer is rebooted instead of appending to the end of it, in case software or hardware changes.
I also want the file to be the computer name, as I plan to write these files to a network drive folder where they all will be stored so they will need to be unique.
I know there are several Gurus here that can help with this faster than I can search the internet for it.
Here is what I have so far.
Set dtmConvertedDate = CreateObject("WbemScriptin g.SWbemDat eTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{imper sonationLe vel=impers onate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
Set colApps = objWMIService.ExecQuery ("Select * from Win32_Product Where Caption Like '%Microsoft Office%'")
Set objAD = CreateObject("ADSystemInfo ")
Wscript.Echo "Computer Name: " & objAD.ComputerName
Wscript.Echo "Current User: " & objAD.UserName
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Wscript.Echo "Manufacturer: " & objSMBIOS.Manufacturer
Next
For Each os in oss
Wscript.Echo "Windows Version: " & os.Caption
dtmConvertedDate.Value = os.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDat e
Wscript.Echo "Install Date: " & dtmInstallDate
Wscript.Echo " OS Serial Number: " & os.SerialNumber
Next
For Each objApp in colApps
Wscript.Echo objApp.Caption, objApp.Version
Next
I would like it to write to a text file or CSV instead, and to overwrite the file each time the computer is rebooted instead of appending to the end of it, in case software or hardware changes.
I also want the file to be the computer name, as I plan to write these files to a network drive folder where they all will be stored so they will need to be unique.
I know there are several Gurus here that can help with this faster than I can search the internet for it.
Here is what I have so far.
Set dtmConvertedDate = CreateObject("WbemScriptin
strComputer = "."
Set objWMIService = GetObject("winmgmts:{imper
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
Set colApps = objWMIService.ExecQuery ("Select * from Win32_Product Where Caption Like '%Microsoft Office%'")
Set objAD = CreateObject("ADSystemInfo
Wscript.Echo "Computer Name: " & objAD.ComputerName
Wscript.Echo "Current User: " & objAD.UserName
For Each objSMBIOS in colSMBIOS
Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
Wscript.Echo "Manufacturer: " & objSMBIOS.Manufacturer
Next
For Each os in oss
Wscript.Echo "Windows Version: " & os.Caption
dtmConvertedDate.Value = os.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDat
Wscript.Echo "Install Date: " & dtmInstallDate
Wscript.Echo " OS Serial Number: " & os.SerialNumber
Next
For Each objApp in colApps
Wscript.Echo objApp.Caption, objApp.Version
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
After some research thru the MSDN I found what I was looking for and submitted it here.
ASKER
I got everything working like I want, but the Office Version.
Its not recording the Microsoft Office Version.
On Error Resume Next
Set objNetwork = CreateObject("WScript.Netw
Set objFSO = CreateObject("Scripting.Fi
strOutputFile = "c:\Test1\TestLoc\" & objNetwork.ComputerName & ".txt"
Const adVarChar = 200
Const MaxCharacters = 255
Set dtmConvertedDate = CreateObject("WbemScriptin
strComputer = "."
Set objWMIService = GetObject("winmgmts:{imper
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
Set colApps = objWMIService.ExecQuery ("Select * from Win32_Product Where Caption Like '%Microsoft Office%'")
Set objAD = CreateObject("ADSystemInfo
Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfig
strArchitecture = GetOSArchitecture(objWMISe
strUsername = GetCurrentUsername(objWMIS
strIPAddress = GetIPAddress(objWMIService
' Computer and User Name
Set objOutput = objFSO.CreateTextFile(strO
objOutput.WriteLine "Username: " & objNetwork.ComputerName
For Each objitem In colitems
strIPAddress = Join(objitem.IPAddress, ",")
objOutput.Writeline "IP and MAC Address: " & strIPAddress
Next
For Each objSMBIOS in colSMBIOS
objOutput.Writeline "Manufacturer: " & objSMBIOS.Manufacturer
objOutput.Writeline "Serial Number: " & objSMBIOS.SerialNumber
Next
For Each os in oss
objOutput.Writeline "Windows Version: " & os.Caption
dtmConvertedDate.Value = os.InstallDate
dtmInstallDate = dtmConvertedDate.GetVarDat
objOutput.Writeline "Install Date: " & dtmInstallDate
objOutput.Writeline "OS Serial Number: " & os.SerialNumber
Next
For Each objApp in colApps
objOutput.Writeline "Office Versions: " & objApp.Caption, & objApp.Version
Next