Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

String manipulation in Powershell (video) from class provides some background. U

ID: 3727645 • Letter: S

Question

String manipulation in Powershell (video) from class provides some background. Use the remote course VM at auvm.techcats.solution to update the ExtractString.ps1 script begun in TechPrac03 (if you develop your script elsewhere, no problem, but deploy the script and test folder to our course VM when completed). Work with string logic to update this script so just the text after the search keyword (up to the next space or end of line) appears when the search keyword is found. This should work when there are multiple versions of the search keyword in a line. Make sure the test

.ExtractString.ps1 C:TEMPAIST2330TP03ExtractTest xyzpdq

produces the right result (grab a screen cap of your run) since I will use this to test your script.

Explanation / Answer

option 1:

Get-ChildItem -recurse | Get-Content | Select-String -pattern "xyzpdq"

#pipe your content

You will see that the path is already being returned as a property of the objects.

IF you want just the path, use select path or select -unique path to remove duplicates:

option 2:

Below snippet will display the path, filename and the content line it found that matched the pattern.