0
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.
Where do you want to add which lines? – harrymc – 2018-11-05T15:51:25.397
A simple
gci 'C:\Users\xxx\*.rdl' -r|sls -Pattern '/Documents/'
should already do what you want. – LotPings – 2018-11-05T16:16:52.673I wish to add the line for every file that contains the string "documents". But I can't get it to work. The output needs to be in two columns if possible. One with the path of the file and the other with the line that contains the string. – Nora Seinfield – 2018-11-05T19:58:46.443