These days in see PowerShell, feel very strong, a small task, is to use PowerShell to implement multiple files to retrieve thousands of lines of records in the script. Just beginning to use get-content combined with where-object to achieve, found that the results of the search is too slow, and the retrieved entries are not known from which file, although it is easy to achieve, but after the exploration of a variety of methods, I found out that a powerful command could achieve all of these needs, and that it was super fast.
Generally used for IIS log analysis, because the main introduction of this PS command, IIS log is crawled from the server side, here is only half the test data.
First go to the directory and view the files in the current directory, where four log files are used for testing. As follows:
Then use the following command to achieve that powerful feature:
For example, to search for keyword write, then enter the write return, the results of the search is as follows (only the interception section, here due to privacy, the log file is made by me, but the amount of data is relatively large, the content is purely fictitious ~ ~):
You can assign this statement to a temporary variable to see how much data is detected at this instant:
In fact, there are not many, 4 log files found in the Instant 500 data, in fact, this can not be seen, because I made the amount of data is not big enough ...
The following is a simple explanation for this powerful command:
The whole is actually used select-string This command, the specific use of reference:
Http://technet.microsoft.com/zh-cn/library/dd315403.aspx
Get-childitem is to get all the items in the current face and then through the pipe | Input to? (is Where-object alias) to filter, and filter the current directory log files, $_ represents the current object, that is, the results of the previous detection,-like use pattern matching, $ (read-host) is read from the console, similar to C # ReadLine () (the corresponding standard output is write-host), that is, when the user enters a keyword, the command executes from the back forward.
Because it is just getting started, if there is a mistake, the great God to teach a lot.