I'm quite new with powershell, and I need to help my colleague finding all files in a folder that contains the word /Documents/
.
The output has to be in a text file containing both the path and the line in that file.
As a start I've managed to extract the paths using the following code. But I can't manage to include the following lines:
$path = 'C:\Users\XXX'
$Text =”/Documents/"
$PathArray = @()
Get-ChildItem $path -Filter *.rdl -Recurse |
ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $Text ){
$PathArray += $_.FullName
$PathArray += $_.FullName
#write-Host "jhk"
}
$PathArray | % {$_} | Out-File "C:\Users\XX\tes2.txt"-Append
}
Write-Host "Contents of ArrayPath:"
$PathArray | ForEach-Object {$_}
This code works, but as said, I'm not sure how to add the lines as well.
Best Answer
It's critical that if you are new, that you first spend the time to ramp up to prevent a lot of unnecessary frustration and confusion you are going to encounter.
Do a search on Microsoft Virtual Academy on PowerShell and YouTube for no cost video training.
Here are some other resources and advice:
See also: The PowerShell Survival Guide
As for a specific example on your question. How about this approach?