A website administrator has an output of an FTP session that runs nightly to download and unzip files to a local staging server.
The download includes thousands of files, and the manual process used to find how many files failed to download is time-consuming.
The administrator is working on a PowerShell script that will parse a log file and summarize how many files were successfully downloaded versus ones that failed.
Which script will read the contents of the file one line at a time and return a collection of objects?
Click on the arrows to vote for the correct answer
A. B. C. D.D.
The correct answer is D. Get-Content ""Path \Server\FTPFolder\Logfiles\ftpfiles.log | Select-String "ERROR", "SUCCESS".
Explanation:
The script needs to read the contents of the log file one line at a time, so the "Get-Content" cmdlet is used. This cmdlet reads the contents of a file and returns each line as a separate string object.
The path to the log file is provided by the parameter after the "-Path" flag. In this case, the path is "\Server\FTPFolder\Logfiles\ftpfiles.log".
The "Select-String" cmdlet is used to search for specific patterns or strings within the text of the log file. In this case, the patterns to search for are "ERROR" and "SUCCESS", which represent the two possible outcomes of the file downloads.
The "Select-String" cmdlet returns a collection of objects, each representing a line in the log file that contains one of the search patterns. This collection can then be further processed or manipulated as needed by the script.
Options A, B, and C do not use the correct syntax for the "Get-Content" cmdlet or the "Select-String" cmdlet, and do not provide the necessary functionality to read the log file and search for specific patterns. Therefore, they are incorrect answers.