[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need a write to text file solution . . .

Posted on 2006-06-12
2
Medium Priority
?
898 Views
Last Modified: 2012-05-05
Currently this is my script:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("floyd_adamsxp","ALEX_KHAZAN_XP")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
        WScript.Echo "Name: " & objItem.Name
       WScript.Echo "Model: " & objItem.Model
Next
Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
    Wscript.Echo "Asset Tag: " & objSMBIOS.SMBIOSAssetTag
Next
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
     Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
   Next
Next


Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
      WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
      Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
      & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

What I would like to do is export the data to a text file, but I've been having a difficult time doing it for some reason.  Please help.  Lots of points!
0
Comment
Question by:campbe07
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 2000 total points
ID: 16885578
Hi,

How about something like...

Dim objFileSystemObject
Dim objFSO_TextFile
Dim strLog_Filename

strLog_Filename                         = "C:\Output.txt"

Set objFileSystemObject                    = CreateObject("Scripting.FileSystemObject")

If Not (objFileSystemObject.FileExists(strLog_Filename)) Then
   Set objFSO_TextFile                    = objFileSystemObject.CreateTextFile(strLog_Filename)
   Set objFSO_TextFile                    = Nothing
End If  

Set objFSO_TextFile                    = objFileSystemObject.OpenTextFile(strLog_Filename, 2) ' 2 = ForWriting
'Set objFSO_TextFile                    = objFileSystemObject.OpenTextFile(strLog_Filename, 8) ' 8 = ForAppending

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("floyd_adamsxp","ALEX_KHAZAN_XP")
For Each strComputer In arrComputers

objFSO_TextFile.WriteLine ""
objFSO_TextFile.WriteLine "=========================================="
objFSO_TextFile.WriteLine "Computer: " & strComputer
objFSO_TextFile.WriteLine "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
        objFSO_TextFile.WriteLine "Name: " & objItem.Name
        objFSO_TextFile.WriteLine "Model: " & objItem.Model
   Next
Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
        objFSO_TextFile.WriteLine "Asset Tag: " & objSMBIOS.SMBIOSAssetTag
Next
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
    objFSO_TextFile.WriteLine "Serial Number: " & objBIOS.SerialNumber
   Next
Next

objFSO_TextFile.Close

Set objFSO_TextFile                    = Nothing
Set objFileSystemObject                    = Nothing

Function WMIDateStringToDate(dtmDate)
WScript.Echo dtm:
     WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
     Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
     & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16890112
I trust that suggestion met your requirements.

Thanks for closing the question.

BFN,

fp.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

834 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