Solved

Making a vbscript Wscript write to file instead of Echo

Posted on 2013-01-16
3
1,153 Views
Last Modified: 2013-01-16
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("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & 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.GetVarDate
    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
0
Comment
Question by:Moordoom
  • 3
3 Comments
 

Author Comment

by:Moordoom
ID: 38783649
Ok here is where I am so far.

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.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strOutputFile = "c:\Test1\TestLoc\" & objNetwork.ComputerName & ".txt"

Const adVarChar = 200
Const MaxCharacters = 255

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & 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")
Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
strArchitecture = GetOSArchitecture(objWMIService)
strUsername = GetCurrentUsername(objWMIService)
strIPAddress = GetIPAddress(objWMIService)

' Computer and User Name

    Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
   
      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.GetVarDate
          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
0
 

Accepted Solution

by:
Moordoom earned 0 total points
ID: 38784350
Well, I answered my own question.

Here is my final answer / Script.
It gives you Make, Model and Serial number of the PC/Server, IP and MAC Address, Windows OS Version, and Service Pack, Install Date, OS Serial Number (Not Product Number) and Microsoft Office Version (if installed).

Enjoy  

'Parameters

On Error Resume Next

Set objNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strOutputFile = "\\SWC1FBV\COMMON\SerialNumberScript\" & objNetwork.ComputerName & ".txt"



Const adVarChar = 200
Const MaxCharacters = 255

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product Where Caption Like '%Microsoft Office%'")
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 colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
Set colmodels = objWMIService.ExecQuery("Select * from Win32_Computersystem")
strArchitecture = GetOSArchitecture(objWMIService)
strUsername = GetCurrentUsername(objWMIService)
strIPAddress = GetIPAddress(objWMIService)

' Computer and User Name

    Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
   
      objOutput.WriteLine "Username: " & objNetwork.ComputerName
    For Each objitem In colitems
         strIPAddress = Join(objitem.IPAddress, ",")
         objOutput.Writeline "IP and MAC Address: " & strIPAddress
    Next
      For Each Models In colModels
            objOutput.Writeline "Model Number: " & Models.Model
      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
            objOutput.Writeline "OS Serial Number: " & os.SerialNumber
    Next
    For Each objOperatingSystem in colOperatingSystems
            objOutput.Writeline "Windows Service Pack Version: " & objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion
            objOutput.Writeline "Windows Install Date: " & objOperatingSystem.InstallDate
    Next
    For Each objItem in colSoftware
            objOutput.Writeline " "
            objOutput.Writeline "Name: " & objItem.Name
            objOutput.Writeline "Version: " & objItem.Version
    Next
0
 

Author Closing Comment

by:Moordoom
ID: 38784358
After some research thru the MSDN I found what I was looking for and submitted it here.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now