added Multithread variant for PS 5.x

This commit is contained in:
2026-03-31 22:12:46 +02:00
commit 0a110a5512
2 changed files with 62 additions and 0 deletions

28
Parallel-ps5.ps1 Normal file
View File

@@ -0,0 +1,28 @@
$urls = @(
"www.google.de"
"www.amazon.de"
"www.github.com"
"www.youtube.com"
"www.gibtsnicht.com"
)
$start = Get-Date
$jobs = foreach( $url in $urls ){
Start-Job -ScriptBlock {
param($u)
if(Test-Connection -ComputerName $u -Quiet){
"$u is reachable"
}else{
"$u is not reachable"
}
} -ArgumentList $url
}
$jobs | Wait-Job | Receive-Job
$end = Get-Date
$duration = $end - $start
Write-Host "Laufzeit: $($duration.TotalSeconds)"

34
Parallel.ps1 Normal file
View File

@@ -0,0 +1,34 @@
$urls = @(
"www.google.de"
"www.amazon.de"
"www.github.com"
"www.youtube.com"
"www.gibtsnicht.com"
)
$start = Get-Date
$urls | ForEach-Object -Parallel {
$reachable = Test-Connection -ComputerName $_ -Quiet
if($reachable){
Write-Host "$($_) is reachable"
}else {
Write-Host "$($_) could not be reached"
}
}
<#
$urls | ForEach-Object {
$reachable = Test-Connection -ComputerName $_ -Quiet
if($reachable){
Write-Host "$($_) is reachable"
}else {
Write-Host "$($_) could not be reached"
}
}
#>
$end = Get-Date
$duration = $end - $start
Write-Host "Laufzeit: $($duration.TotalSeconds)"