Open Eperrial opened 5 years ago
The vars $tableaux is not aware in the threads (runspaces). You can try to use Receive-RSJob as shown in the readme.md
it's not easy when it's the first time with powershell ! aha ^^
Thanks for this !
`$ADCheck=@(Get-ADComputer -filter "*" -Properties IPv4address -SearchBase "OU=COMPUTERS,DC=adep,DC=local" |Where-Object {$.ipv4address} | Select-Object -ExpandProperty ipv4address ) $oui = $ADCheck | Start-RSJob -Name {$} -Throttle $env:NUMBER_OF_PROCESSORS -ScriptBlock { param([string]$ip) if(Test-Connection -Count 1 -ComputerName $ip -Quiet) {
try {
if(Get-Service -Name oui)
{
#Write-Host "L'ordinateur d'ip : $ip à bien reussi le test du ping et du service"
[PSCustomObject]@{
Name = $ip
Ping = "Ok"
Service = "Ok"
}
}
else
{
#Write-Host "L'ordinateur d'ip : $ip à échoué dans le test du service mais est accessible !"
[PSCustomObject]@{
Name = $ip
Ping = "Ok"
Service = "Erreur"
}
}
}
catch{}
}
else
{
#Write-Host "Ping sur $ip : Echoue"
[PSCustomObject]@{
Name = $ip
Ping = "Erreur"
Service = "Erreur"
}
}
}| Wait-RSJob | Receive-RSJob `
glad to see this works for you, please close the issue if it is resolved.
Hello,
I am a student in DUT Networks and telecommunication and also a beginner in powershell. (FR : DUT / UK : DHE / US : AD ) After a few hours of searching the Internet, I would like to display the different tables in the RSJob.
i have this return on my terminal, someone can guide me ? :)
( the code on plain text if someone want to edit )
$ADCheck=@(Get-ADComputer -filter "*" -Properties IPv4address -SearchBase "OU=COMPUTERS,DC=test,DC=local" |Where-Object {$_.ipv4address} | Select-Object -ExpandProperty ipv4address ) $TableauEchP=@() $TableauRPES=@() $TableauRPRS=@() $ADCheck | Start-RSJob -Name {$_} -Throttle $env:NUMBER_OF_PROCESSORS -ScriptBlock { param($ip)[string] if(Test-Connection -Count 1 -ComputerName $ip -Quiet) { try { if(Get-Service -Name test) { $TableauRPRS += $ip } else { $TableauRPES += $ip } } catch{} } else { $TableauEchP += $ip } } Get-RSJob | Wait-RSJob Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////" Write-Host "This is IP as all test on TRUE" $TableauRPRS Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////" Write-Host "Ping : TRUE - Service : FALSE" $TableauRPES Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////" Write-Host "Ping : FALSE, check computer if is up" $TableauEchP Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////"