Here’s the part you’re really interested in. We then create an instance of the FileSystemObject, and use the OpenTextFile method to open the file C:\Scripts\Servers.txt. Like your current script, we create a constant (ForReading) and assign it the value 1 this is required when using the FileSystemObject to read a text file. So can you read the text file all at once, store that information in a variable, and then work with the list of computers from memory? Of course you can: Const ForReading = 1 Not only will you have to continually travel across the network just to read a single line out of a text file, but if that remote computer goes down, then your script goes down as well. After all, suppose the text file is located on a remote computer. However, we can understand why you might want to read the text file all at once and then work with the list in memory. Now, there’s nothing wrong with reading a text file this way it works just fine. Set objFSO = CreateObject(“Scripting.FileSystemObject”) (In your script, of course, you probably connect to that remote computer at this point.) We then read in the second line of the text file, echo the name of that computer, loop around, read in the third line of the text file, and continue in this vein until we’ve finished reading each line in the file: Const ForReading = 1 In this sample script, we open a text file (servers.txt), read the first line (we’re also assuming that there is one computer name per line in the file), and then echo the name of the computer. We’re assuming that your script currently looks something like this one. Is there a way to store those names in a variable or something, so that I don’t have to keep reading the text file? The script reads the first line of the file and connects to that computer, then reads the second line of the file and connects to that computer. Hey, Scripting Guy! Right now I use a script to open a text file containing computer names.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |