I have code, which uses this tool https://learn.microsoft.com/en-us/sysinternals/downloads/strings :
$listOfFiles=(Get-ChildItem -Path 'C:\Program Files\test' -Include "*.dll","*.exe" -recurse | ForEach-Object {$_.FullName})
Foreach($file in $listOfFiles)
{
strings.exe -n 10 $file >> test.txt
}
How can I put results from 'strings.exe -n 10 $file' command to the array?
Because later I would like to display them in my created csv table.
CodePudding user response:
Use Select-Object
to create 1 new object per string output by strings.exe
, then assign all the output from the entire loop to a single variable:
$listOfFiles = Get-ChildItem -Path 'C:\Program Files\test' -Include "*.dll","*.exe" -Recurse |ForEach-Object FullName
$strings = foreach($file in $listOfFiles)
{
strings.exe -n 10 $file |Select-Object @{Name='String';Expression={$_}},@{Name='FilePath';Expression={$file}}
}