From 070de5d0bdf3d7e401598de85035a1fd7b6fb513 Mon Sep 17 00:00:00 2001 From: Derek-Charlekston Date: Wed, 30 Aug 2017 17:26:53 -0500 Subject: [PATCH] Create get-ping.ps1 --- get-ping.ps1 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 get-ping.ps1 diff --git a/get-ping.ps1 b/get-ping.ps1 new file mode 100644 index 0000000..77e3e59 --- /dev/null +++ b/get-ping.ps1 @@ -0,0 +1,53 @@ +Function Get-PingStatus + { + param( + [Parameter(ValueFromPipeline=$true)] + [string]$device, + + [validateSet("Online","Offline","ObjectTable")] + [String]$getObject + ) + +begin{ + $hash = @() + + } +process{ + + $device| foreach { + if (Test-Connection $_ -Count 1 -Quiet) { + + if(-not($GetObject)){write-host -ForegroundColor green "Online: $_ "} + + $Hash = $Hash += @{Online="$_"} + }else{ + + if(-not($GetObject)){write-host -ForegroundColor Red "Offline: $_ "} + + $Hash = $Hash += @{Offline="$_"} + } + } + } + +end { + if($GetObject) { + + $Global:Objects = $Hash | foreach { [PSCustomObject]@{ + + DeviceName = $_.Values| foreach { "$_" } + Online = $_.Keys| where {$_ -eq "Online"} + offline = $_.Keys| where {$_ -eq "Offline"} + } + } + + Switch -Exact ($GetObject) + { + + 'Online' { $Global:Objects| where 'online'| select -ExpandProperty DeviceName } + 'Offline' { $Global:Objects| where 'offline'| select -ExpandProperty DeviceName } + 'ObjectTable' { return $Global:Objects } + } + + } + } +}