Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array in scriptbloc #202

Open
Eperrial opened this issue Aug 5, 2019 · 3 comments
Open

Array in scriptbloc #202

Eperrial opened this issue Aug 5, 2019 · 3 comments

Comments

@Eperrial
Copy link

Eperrial commented Aug 5, 2019

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.

image

i have this return on my terminal, someone can guide me ? :)

image

( 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 "//////////////////////////////////////////////////////////////////////////////////////////////////"

@copdips
Copy link
Contributor

copdips commented Aug 5, 2019

The vars $tableaux is not aware in the threads (runspaces).
You can try to use Receive-RSJob as shown in the readme.md

@Eperrial
Copy link
Author

Eperrial commented Aug 5, 2019

it's not easy when it's the first time with powershell ! aha ^^

image

Thanks for this !

( the code on plain text if someone want to copy )

$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) { #Write-Host "Ping sur $ip Reussi" 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

@copdips
Copy link
Contributor

copdips commented Aug 6, 2019

glad to see this works for you, please close the issue if it is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants