Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Get-Pingables {
- [cmdletbinding()]
- Param(
- [parameter(Mandatory=$True, ValueFromPipeline = $True, Position = 0)]
- [String[]]$ComputerName,
- [switch]$Online
- )
- $pingable = [System.Collections.Generic.List[PSObject]]::new()
- $ComputerName | ForEach-Object {
- Set-Variable -Name "Status_$_" -Value (Test-Connection -ComputerName $_ -AsJob -Count 1)
- }
- Get-Variable "Status_*" -ValueOnly | ForEach-Object {
- $Status = Wait-Job $_ | Receive-Job
- $reachable = $False
- $addr = ""
- if ($Status.ResponseTime -ne $null ) {
- $addr = $Status.Address
- $reachable = $True
- }
- $pingable.add([PSCustomObject]@{'Computer' = $Status.Address; 'Online' = $reachable})
- }
- if ($Online) {
- Return $pingable | Where-Object { $_.Online } | Select-Object Computer
- } else {
- Return $pingable | Sort-Object -Descending -Property 'Online'
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement