Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Custom_Polling {
- [string]$Device
- [string]$Status
- Custom_Polling([string]$Device) {
- $this.Device = $Device
- $this.Status = $this.Pulse($Device)
- }
- [string] Pulse($Device) {
- try {
- $job = Start-Job -ScriptBlock {
- param($Device)
- Test-NetConnection -ComputerName $Device -Port 22
- } -ArgumentList $Device | Wait-Job -Timeout 5
- #
- if ((Get-Job -Id $job.Id).State -eq 'Completed') {
- $result = 'UP'
- }
- else {
- $result = 'DOWN'
- }
- }
- catch {
- $job = Get-Job -Command "Test-NetConnection -Computername $Device -Port 22"
- $result = 'ERROR'
- }
- finally {
- if ($null -ne $job) {
- Remove-Job -Id $job.id
- }
- }
- return $result
- }
- }
- function Invoke-Polling {
- <#
- Query devices for SSH open and available and store as Polling active or down
- #>
- param ([Parameter(Mandatory=$True)][string]$Path)
- if (Test-path -path $path) {
- $Devices = Get-Content -Path $Path
- }
- $obj = New-Object System.Collections.ArrayList
- foreach ($Dev in $Devices) {
- $poll = [Custom_Polling]::new($Dev)
- $obj.Add($poll)
- }
- Write-Output $obj
- }
Advertisement
Add Comment
Please, Sign In to add comment