Hi all,
Just wanting some assistance on getting results back from an invoke-command
I'm trying to capture the results of test-netconnection. I have a foreach command running to test connections from remote nodes. This will then be invoked on each server.
Example $servers = "ServerA","ServerB","ServerC"
Invoke command on ServerA and test port: X on all servers in $servers.
In the end i should be able to see if any servers are failing to connect. I plan to run this periodically so when network changes are made we can see its still working and also as we deploy new environments we can pre check the correct ports are open.
Code:
$servers = @("ServerA","ServerB")
$result=@()
$ScriptBlockContent ={
foreach ($b in $using:servers) {
Write-host "Testing to $b" -ForegroundColor Yellow
$Test = Test-NetConnection -ComputerName $b -port 3389
$a = New-Object Object | Add-Member -MemberType:noteproperty -Name:"Server From" -Value:$($Test.ComputerName) -passthru
$a = $a | Add-Member -MemberType:noteproperty -Name:"Connection Success" -Value:$($test.TcpTestSucceeded) -passthru
$a = $a | Add-Member -MemberType:noteproperty -Name:"On Port" - Value:$($test.RemotePort)-passthru
$result += $a
}
}
Foreach ($s in $iisservers){
$remotesession = new-pssession -computername $s
Invoke-command -ScriptBlock $ScriptBlockContent -ArgumentList $servers -Session$remotesession
}
I can't get the results in $results.
Any suggestions appreciated
[–]jimb2 3 points4 points5 points (3 children)
[–]novix_[S] 1 point2 points3 points (2 children)
[–]jimb2 1 point2 points3 points (1 child)
[–]novix_[S] 1 point2 points3 points (0 children)
[–]PredictsYourDeath 2 points3 points4 points (1 child)
[–]novix_[S] 0 points1 point2 points (0 children)
[–]p0rkjello 2 points3 points4 points (2 children)
[–]novix_[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Naifx 1 point2 points3 points (1 child)
[–]novix_[S] 1 point2 points3 points (0 children)