How can you modify the provided script to return information about one or more remote PCs? The answer lies in the script's strComputer line, which specifies the target computer. By default, Scriptomatic sets this line of code (at callout A in Listing 2) to ".", indicating the current PC. To check a remote PC instead, change "." to the full DNS name of the remote PC"anotherpc.emea.mycorp.com", for example. What about checking multiple PCs? If you want to check only a dozen PCs, you can add them to the script as an array and cycle through each one in turn. However, if you want to check more PCssay, all the PCs in a specific OUyou need a way to retrieve all those long DNS names from AD. That requirement takes us back to Csvde, which you can use to export the names of all the PCs in a certain group, a certain OU, or the entire network.
Suppose that you want to find all the PCs listed in AD, then pull out the OS Caption and Version information from each one. You can do so by using Csvde and a modification to the Scriptomatic-generated WMI Win32_OperatingSystem script. The script that Listing 3, page 5, shows uses Csvde to extract the list of client PCs to a .csv file, opens that file in Excel (placing the information about each PC in a new row), and reads the file line by line. The script then uses WMI to try to connect to each PC and read the OS data. The script writes the results to a second Excel spreadsheet, indicating for each PC whether the script could connect to the PC and providing the OS data for those PCs to which it could connect.
The script begins by declaring the necessary constants and variables. You'll need to change the specified PATH, CSV, XLS, and AD_ROOT variable values to ones that are appropriate for your environment.
The script then uses the WSH Shell::Run method to run Csvde, ensuring that the Run window remains hidden and that the script's execution pauses until Csvde has finished running. The script uses the Csvde string that I described earlier but sets the filter (-r) to search for computers and the property to be returned (-l) to the PCs' long DNS names.
After the script populates the .csv file, it creates an Excel Application object, opens the .csv file, and saves the file as an .xls file, closing the original .csv file in the process. The script then uses the standard FileSystemObject::DeleteFile call to delete the .csv file and the csv.log file.
The .xls file has one sheet containing the PC data. This data includes an extra first column containing each returned item's distinguished name (DN) and an extra header row identifying each returned item. We don't need this information in our report, so the script deletes the first column and first row.
Now the .xls file contains the data we need in one worksheet named Machines (or whatever you called your .csv fileExcel opens the .csv file into one worksheet and gives that worksheet whatever name you gave the .csv file). Because only one worksheet exists, the script can rename the sheet (with a more descriptive name such as OS Details for All PCs, for example) simply by selecting all worksheets and renaming the active sheet. I also need to create a heading row, so the script inserts a new first row, shifting all the other cells down. The script then inserts column headings into the empty row and formats those cells, as I described for Listing 2.
Now we're ready to begin adding data, starting at Row 2. The script uses a While loop to determine whether the first cell in that row (i.e., cell A2) is empty. If notin other words, if the cell contains a PC namethe script continues, setting the strComputer object to the name in the cell and attempting to use the Scriptomatic WMI code to retrieve data from that system. Before entering the loop, the script confirms that the objWMIService object isn't equal to Nothing. If the object is equal to Nothing, the script increments the rowcount and skips to the next row. (Inside the While loop, the script sets the objWMIService object to Nothing after each pass. Otherwise, if WMI failed to connect to a remote PC, the object would fail to loop to the next machine in line.)
Prev. page
1
2
[3]
4
next page