I am trying to print an array (I tried both with a for loop and directly with .ToString()), but I allways get a System.Object output.
The content of the array is the result of this command:
$singleOutput = Invoke-Command -ComputerName $server -ScriptBlock {
Get-ChildItem C:\*.txt -Recurse |
Select-String -Pattern "password" -AllMatches
}
This is the output I'm getting:
System.Object[]
What am I missing?
EDIT:
This is the whole function:
foreach ($server in $servidores) {
$result = @()
Write-Output ("---Searching on Server:---" + $server + "----at:" +
(Get-Date).ToString() + "----")
$singleOutput = Invoke-Command -ComputerName $server -ScriptBlock {
Get-ChildItem C:\*.txt -Recurse |
Select-String -Pattern "password" -AllMatches
}
$result += $singleOutput
Write-Host $result.ToString()
}
Read-Host -Prompt "Press Enter to exit"
I also tried with:
foreach ($i in $result) {
$result[$i].ToString()
}
"$result"instead of$result.ToString()Write-Host $result.toString(), use eitherWrite-Host ($result -join "`r`n")or$result.