300-215 · Question #1
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…
The correct answer is D. Get-Content -Path \\Server\FTPFolder\Logfiles\ftpfiles.log | Select-String "ERROR", "SUCCESS". The PowerShell cmdlet Get-Content reads content line-by-line from a file and is commonly used for processing logs or large text files. When combined with Select-String, it can search for specific patterns (such as "ERROR" or "SUCCESS") within those lines and return a collection…
Question
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?
Options
- AGet-Content-Folder \Server\FTPFolder\Logfiles\ftpfiles.log | Show-From "ERROR", "SUCCESS"
- BGet-Content -ifmatch \Server\FTPFolder\Logfiles\ftpfiles.log | Copy-Marked "ERROR",
- CGet-Content -Directory \Server\FTPFolder\Logfiles\ftpfiles.log | Export-Result "ERROR",
- DGet-Content -Path \Server\FTPFolder\Logfiles\ftpfiles.log | Select-String "ERROR", "SUCCESS"
How the community answered
(34 responses)- A6% (2)
- B3% (1)
- C3% (1)
- D88% (30)
Explanation
The PowerShell cmdlet Get-Content reads content line-by-line from a file and is commonly used for processing logs or large text files. When combined with Select-String, it can search for specific patterns (such as "ERROR" or "SUCCESS") within those lines and return a collection of matching objects, including metadata like line number and line content. Get-Content -Path: Correct syntax to read the log file from a UNC path. Select-String "ERROR", "SUCCESS": Searches for these terms in each line and returns matching lines as structured
Topics
Community Discussion
No community discussion yet for this question.