Announcement

Collapse
No announcement yet.

Save output of a script to a file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Save output of a script to a file

    I'm hoping you guys can help. I'm looking to write a script to get the model of a computer from the BIOS and save it in a text file. I was able to write the script to display the model however I can't get it to save in a file. Can anyone help me?

    Here is the script

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
    For Each objComputer in colSettings



    Wscript.Echo "System Model: " & objComputer.Model

    Next

  • #2
    Re: Save output of a script to a file

    That's pretty simple...take a look here for other examples: http://www.activexperts.com/activmon...her/textfiles/

    But this is how you would do it:

    Code:
    strComputer = "."
    
    Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colSettings = objWMIService.ExecQuery _
       ("Select * from Win32_ComputerSystem")
    
    strFile = "C:\model.txt"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile(strFile)
    
    For Each objComputer in colSettings
       objFile.WriteLine "System Model: " & objComputer.Model
    Next
    
    objFile.Close
    
    msgbox "done!"
    WScript.quit

    Comment


    • #3
      Re: Save output of a script to a file

      Thanks ekrengel. Works perfectly.

      Comment

      Working...
      X