Чтобы ваша переменная имела смысл для powershell , вам необходимо заменить
$result = @($comp,$version,$user)
на
New-Object psobject -Property @{'ComputerName'=$comp;
'Version'=$version;
'User'=$user}
Причина в том, что выне определяя, какими свойствами является каждая переменная, просто то, что она является переменной, поэтому вывод, который вы получите, будет выглядеть странно.НЕ декалируйте $ result, так как это переменная внутри задания, и это отдельные экземпляры powershell.Этот способ проще.
Чтобы завершить вывод в gridview , вам необходимо передать receive-job
в out-gridview
$comps | ForEach-Object {Start-Job -Scriptblock $scriptblock -ArgumentList $_ | Out-Null}
Get-Job | Wait-Job | Receive-Job | Out-GridView
Вот какЯ бы на самом деле написал ваш сценарий .... С объявив $result
$scriptblock = {
Param($comp)
IF (Test-Connection $comp -Quiet){
$user = (Get-WmiObject -Class win32_computersystem -ComputerName $comp | Select-Object username ).Username
Get-Service -ComputerName $comp -Name "remoteregistry" | start-service -ErrorAction Ignore
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $comp)
$vRegKey= $Reg.OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{19C7ABD4-4445-48B0-9D02-5A706D080688}")
$Version = $vRegKey.GetValue("DisplayName")
Get-Service -ComputerName $comp -Name remoteregistry | stop-service -ErrorAction Ignore
} ELSE { Write-Host "***$comp ERROR -Not responding***" }
$script:result += New-Object psobject -Property @{'ComputerName'=$comp;
'Version'=$version;
'User'=$user}
}
$result = $null
$comps = get-content -path 'C:\temp\hostnames.txt'
$comps | ForEach-Object {Start-Job -Scriptblock $scriptblock -ArgumentList $_ | Out-Null}
Get-Job | Wait-Job
$result | Out-GridView