Saving Script Output to a text file?

This is a question on a previus posting: Q_21545048.html

I am trying to run the script and save the output (serial number) to a text file. I am trying to save it to a network share but am testing in on my local computer \\swernette\scripting.  I have also tried saving it to C:\scripting which is where the scripting folder is located.

The error that I get is:
Script:   C:\SerialNumber.vbs
Line:      9
Char:     2
Error:    Bad file name or number
Code:    800A0034
Source: Microsoft VBScript runtime error

Here is the script:
 set fso = createobject("scripting.filesystemobject")
 arAddresses = GetIPAddresses()

 strComputer = "."
 Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")

 set ts = fso.createtextfile ("\\swernette\scripting\" & araddresses(0))

 For Each objSMBIOS In colSMBIOS
  ts.writeline "Serial Number: " & objSMBIOS.SerialNumber
  ts.writeline "Asset Tag: " & objSMBIOS.SMBIOSAssetTag

 set ts = nothing
 set fso = nothing

Function GetIPAddresses()

' Returns array of IP Addresses as output
' by ipconfig or winipcfg...
' Win98/WinNT have ipconfig (Win95 doesn't)
' Win98/Win95 have winipcfg (WinNt doesn't)
' Note: The PPP Adapter (Dial Up Adapter) is
' excluded if not connected (IP address will be
' and included if it is connected.
  set sh = createobject("")

  Set Env = sh.Environment("PROCESS")
  if Env("OS") = "Windows_NT" then
    workfile = fso.gettempname "%comspec% /c ipconfig > " & workfile,0,true
    'winipcfg in batch mode sends output to
    'filename winipcfg.out
    workfile = "winipcfg.out" "winipcfg /batch" ,0,true
  end if
  set sh = nothing
  set ts = fso.opentextfile(workfile)
  data = split(ts.readall,vbcrlf)
  fso.deletefile workfile
  arIPAddress = array()
  index = -1
  for n = 0 to ubound(data)
    if instr(data(n),"IP Address") then
      parts = split(data(n),":")
      if trim(parts(1)) <> "" then
        index = index + 1
        ReDim Preserve arIPAddress(index)
        arIPAddress(index)= trim(cstr(parts(1)))
      end if
    end if
  GetIPAddresses = arIPAddress
End Function
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I suspect there's a bug in the GetIPAddresses function. It's returning the machines IP address with a CR appended to it which the VB's CreateTextFile function objects to.

To fix, you could either correct the function itself by getting it to take the additional character off the values it returns or, alternatively, do the same thing at the top of the script once you've got the array off the function.  I'd suggest the former as it will ensure that when you re-use the script elsewhere you don't run into the same issue!  Add the following line just below the "arIPAddress(index)= trim(cstr(parts(1)))" line in the function.




Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmushaunAuthor Commented:
That worked wonderfully. I'm just learning scripting so it all seems overwhelming but very intriguing. I may be posting more question to take this project further so be looking for me :-)
No problem cmushaun, I'll keep an eye out for you!  It'll get easier with practice!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.