-
Notifications
You must be signed in to change notification settings - Fork 4
/
Show-ComputerPingChange.ps1
74 lines (57 loc) · 2.08 KB
/
Show-ComputerPingChange.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<#
.SYNOPSIS
This script loops through a computer status, and display reachability status change.
.PARAMETER Computer
The Computer to monitor reachability
.PARAMETER FileName
If specified, logs the ping change into a file
.INPUTS
None. You cannot pipe objects to that script.
.OUTPUTS
.EXAMPLE
C:\PS> .\Full-Name.ps1
Your full name is Merlin the Wizard
.EXAMPLE
C:\PS> .\Full-Name.ps1 -FirstName "Jane" -LastName "Doe"
Your full name is Jane Doe
.EXAMPLE
C:\PS> .\Full-Name.ps1 "Jane" "Doe"
Your full name is Jane Doe
.LINK
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-6
.LINK
https://github.com/SammyKrosoft
#>
Function IsComputerReachable {
[CmdLetBinding(DefaultParameterSetName = "NormalRun")]
Param(
[Parameter(Mandatory = $False, Position = 0, ParameterSetName = "NormalRun")][string]$ComputerName = $($ENV:ComputerName),
[Parameter(Mandatory = $false, Position = 1, ParameterSetName = "CheckOnly")][switch]$CheckVersion
)
If (Test-Connection $ComputerName -Count 1 -ErrorAction SilentlyContinue) {
Return $True
} Else {
Return $False
}
}
Function Show-ComputerStatusChange ($ComputerName,$SleepTime=2) {
$FirstStatus = IsComputerReachable $ComputerName
$CurrentTest = $FirstStatus
$CurrentTime = $((Get-Date).ToString())
Write-Host "Beginning..."
Write-Host "Status => $CurrentTest at $CurrentTime"
While ($True) {
$LastTest = $CurrentTest
$LastTime = $CurrentTime
Sleep $SleepTime
$CurrentTest = IsComputerReachable $ComputerName
$CurrentTime = $((Get-Date).ToString())
# write-host ("Last Test and time") + $LastTime + $LastTest
# Write-Host ("Current Test and time") + $CurrentTime + $CurrentTest
If ($CurrentTest -ne $LastTest){
Write-Host "Status changed - Last status was = $LastTest, and it changed at $CurrentTime to => $CurrentTest" -BackgroundColor Yellow -ForegroundColor Blue
}
}
}
cls
Show-ComputerStatusChange -ComputerName E2010