Solved

Script that reads information from a text file and outputs to another txt file

Posted on 2008-06-23
5
324 Views
Last Modified: 2011-10-19
Hello everyone. I am looking for some assistance with a script. I am using the cscsniff.exe to locate what shares users have their offline files on. My plan is to run a .bat file and output the information to c:\temp on the local system. Once I have run that I want to take the information from the .txt file and output it into another .txt file with all of the information so  that I can search.

I cannot figure out how to get it to pull the information from the txt file. The only items I that I want written to the final output file are the system name and the share information.

For example, I would like for my final log to have the below information.

TestPC1
\\usatl\test$
\\usatl\user1$

Is this possible?

offline.txt
0
Comment
Question by:Lorrec
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 21850725
Try this.

Regards,

Rob.
If WScript.Arguments.Count > 0 Then
	Set arrFiles = WScript.Arguments
Else
	arrFiles = Array( _
		"Offline1.txt", _
		"Offline2.txt" _
		)
End If
 
strOutputFile = "AllOfflines.txt"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intForWriting = 2
Const intForAppending = 8
For Each strFile In arrFiles
	MsgBox strFile
	Set objFile = objFSO.OpenTextFile(strFile, intForReading, False)
	boolGetShares = False
	While Not objFile.AtEndOfStream
		strLine = objFile.ReadLine
		If Left(strLine, 18) = "Status of CSC for " Then
			strComputer = Mid(strLine, 19)
			strComputer = Left(strComputer, InStr(strComputer, " ") - 1)
			strDetails = strDetails & VbCrLf & VbCrLf & strComputer
		End If
		If Left(strLine, 5) = "Share" And InStr(strLine, "Offline?") > 0 Then
			boolGetShares = True
		ElseIf boolGetShares = True And Left(strLine, 7) = "SUMMARY" Then
			boolGetShares = False
		ElseIf boolGetShares = True Then
			strDetails = strDetails & VbCrLf & Trim(Left(strLine, InStr(strLine, "0x") - 2))
		End If
	Wend
	objFile.Close
	Set objFile = Nothing
Next
 
Set objOutputFile = objFSO.OpenTextFile(strOutputFile, intForAppending, True)
objOutputFile.Write strDetails
MsgBox strDetails
objOutputFile.Close
Set objOutputFile = Nothing
 
MsgBox "Done. Please see " & strOutputFile

Open in new window

0
 

Author Comment

by:Lorrec
ID: 21856893
Thank you for the response.

I am getting an error message when I run it. It cannot locate a file.

I assume that I can set my strOutputFile to anything such as c:\temp\AllOfflines.txt. How do I tell it where Offline1.txt is located at?

0
 

Author Comment

by:Lorrec
ID: 21857086
I forgot to mention that my plan was to deploy this through SMS. The offline1.txt will be in the same location on each system. How would I set it up to only look at the offline1.txt at a standard location rather reading multiple ones.

Thanks again for the help.
0
 

Author Closing Comment

by:Lorrec
ID: 31469901
Thank you for the assistance.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21860631
Hi, thanks for the grade. Did you manage to answer your questions? Basically, if you do not define a specific path, it looks by default to the same folder that the script file is located, that it, the current directory.  If you want to use specific named paths, just place the full path there.

For example:
      arrFiles = Array( _
            "C:\Temp\Offline1.txt", _
            "C:\Windows\Temp\Offline2.txt" _
            )

strOutputFile = "\\server\Share\AllOfflines.txt"


Regards,

Rob.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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