Skip to content

Commit

Permalink
Merge fc93e3e into 3fa89b5
Browse files Browse the repository at this point in the history
  • Loading branch information
silversword411 committed Nov 10, 2021
2 parents 3fa89b5 + fc93e3e commit 130a442
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
62 changes: 62 additions & 0 deletions scripts_wip/Win_Network_Connection_Monitor2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<#
.SYNOPSIS
Script that will do the ICMPv4 ping and write to file with timestamps for logging.
.DESCRIPTION
This script will ping the specified host/IP with time stamps. The result will also be written to the log <Destination_PingOutput.txt> file.
Example usage:
.\Smart_Ping.ps1 -ComputerName myServer1 -min 10
This will ping the myServer1 for 10 minutes.
Author: phyoepaing3.142@gmail.com
Country: Myanmar(Burma)
Released: 12/13/2016
.EXAMPLE
.\Smart_Ping.ps1 -ComputerName myServer1 -hr 1 -min 20
This will ping myServer1 for 1 hour and 20 minutes. Buffer size will be 32 bytes by default.
.\Smart_Ping.ps1 192.168.43.1 -size 5000
This will ping 192.168.43.1 10 minutes or 600 seconds by defaut. Buffer size will be 5000 bytes.
.PARAMETER hr
Specify the number of hours to ping a specified host. Decimal number is supported. Eg. -hr 0.5 for 30 minutes.
.PARAMETER min
Specify the number of minutes to ping a specified host. Decimal number is supported. Eg. -hr 0.5 for 30 seconds.
.PARAMETER sec
Specify the number of minutes to ping a specified host.
.LINK
You can find this script and more at: https://www.sysadminplus.blogspot.com/
#>

param([Parameter(Position = 0, Mandatory = $true)][string]$ComputerName, [single]$hr = 0, [single]$min = 0, $sec = 0, [int]$size = 32)

If ($size -gt 65500) { Write-Host -Fore red "Invalid buffer size specified. Valid range is from 0 to 65500."; Exit; } ## If the buffer size is larger than 65500, then exits the script.
If ($hr -eq 0 -AND $min -eq 0 -AND $sec -eq 0) { $min = 10 }
[int]$second = ($hr) * 3600 + $min * 60 + $sec ## Convert Hour/Minute/Second value to seconds
$ts = [timespan]::fromseconds($second) ## Covert second values to h:m:ss
$var1 = "Duration of Ping time is $($ts.ToString("hh\:mm\:ss"))"
$var2 = "Ping from $($env:ComputerName) to $ComputerName at $([datetime]::now)";
Write-Host -fore yellow $var1;
Write-Host -fore yellow $var2;
$var1 | Out-File "$($ComputerName)_PingOutput.txt"; $var2 | Out-File -Append "$($ComputerName)_PingOutput.txt";
$Time = @(); ## Create the array to put the time values at each ping
############## Ping the specific host and manipulate output #################
Ping -t $ComputerName -n $second -l $size | where { !($_ -match "ping" -OR $_ -Match "packets" -OR $_ -Match "Approximate" -OR $_ -Match "Minimum" -OR $_ -eq "") } | foreach {
If ($_ -match "reply") { "$(([datetime]::now) ) $_" } else { "$(([datetime]::now) ) $_" }
$TimePiece = $_.Split(' ') -match "time"
############## Fetch the ping packet round trip time and place into the variable #########
If ($TimePiece -match "<") {
$Time += $TimePiece.split('<')[1].trimEnd('ms')
}
elseif ($TimePiece -match '=') {
$Time += $TimePiece.split('=')[1].trimEnd('ms')
}
} | Tee-Object -Append "$($ComputerName)_PingOutput.txt"
############# Calculate the the manimum, maximum & avarage ######################
$LastLine = "Maximum = $(($Time | measure -maximum).maximum)ms, Minimum = $(($Time | measure -minimum).minimum)ms, Average = $([int]($Time | measure -average).average)ms"
$LastLine | Out-File -Append "$($ComputerName)_PingOutput.txt"
Write-Host -fore yellow $LastLine
53 changes: 53 additions & 0 deletions scripts_wip/Win_Network_Connection_Monitoring.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function Start-ConnectionMonitoring {
param($isp, $gateway, $Logfile, [int]$Delay = 10, [Ipaddress] $adapter, [switch]$ispPopup, [switch]$gateWayPopup)
$spacer = '--------------------------'
while ($true) {
if (!(Test-Connection $gateway -source $adapter -count 1 -ea Ignore)) {
get-date | Add-Content -path $Logfile
"$gateWay Connection Failure" | add-content -Path $Logfile
$outagetime = Start-ContinousPing -address $gateway -adapter $adapter -Delay $Delay
"Total Outage time in Seconds: $outageTime" | Add-Content -path $Logfile
if ($gateWayPopup) {
New-PopupMessage -location $gateway -outagetime $outagetime
}
$spacer | add-content -Path $Logfile
}
if ((!(Test-Connection $isp -Source $adapter -count 1 -ea Ignore)) -and (Test-Connection $gateway -count 1 -ea Ignore)) {
get-date | Add-Content -path $Logfile
"$isp Connection Failure" | Add-Content -Path $Logfile
$outagetime = Start-ContinousPing -address $isp -adapter $adapter -Delay $Delay
"Total Outage time in Seconds: $outageTime" | Add-Content -path $Logfile
if ($ispPopup) {
New-PopupMessage -location $isp -outagetime $outagetime
}
$spacer | add-content -Path $Logfile


}
Start-Sleep -Seconds $Delay
}
}

function Start-ContinousPing {
param($address, [ipaddress] $adapter, [int]$Delay = 10)
$currentTime = get-date
While (!(Test-Connection $address -Source $adapter -count 1 -ea Ignore)) {
Sleep -Seconds $Delay
}
$outageTime = ((get-date) - $currentTime).TotalSeconds
$outageTime
}
function New-PopupMessage {
param($location, $outagetime)
$Popup = New-Object -ComObject Wscript.Shell
$popup.popup("$location Failure - seconds: $outagetime ", 0, "$location", 0x1)
}

$Logfile = "c:\temp\connection.log"
$isp = 'google.com'
if (!(test-path $Logfile)) {
new-item -Path $Logfile
}
$IP = (Get-NetIPConfiguration -InterfaceAlias 'Ethernet').ipv4address.ipaddress
$gateway = (Get-NetIPConfiguration).ipv4defaultGateway.nexthop
Start-ConnectionMonitoring -isp $isp -gateway $gateway -Logfile $Logfile -adapter $IP -ispPopup -gateWayPopup
4 changes: 4 additions & 0 deletions scripts_wip/Win_Windows_Update_RevertToDefault.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Tactical RMM Patch management disables Windows Automatic Update settings by setting the registry key below to 1.
# Run this to revert back to default

Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "AUOptions" -Value "0"

0 comments on commit 130a442

Please sign in to comment.