From 8735d0d6a5653f0efeea4732eba260f37ef8f7e7 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Fri, 27 Aug 2021 15:00:49 +0200 Subject: [PATCH] Add restart-network-adapters.ps1 --- Data/scripts.csv | 1 + README.md | 1 + Scripts/restart-network-adapters.ps1 | 32 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 Scripts/restart-network-adapters.ps1 diff --git a/Data/scripts.csv b/Data/scripts.csv index f34cb715..b55bfa09 100644 --- a/Data/scripts.csv +++ b/Data/scripts.csv @@ -175,6 +175,7 @@ new-email.ps1, starts the default email client to write a new email reboot.ps1, reboots the local computer (needs admin rights) reboot-fritzbox.ps1, reboots the FRITZ!box device remove-empty-dirs.ps1, removes empty subfolders within the given directory tree +restart-network-adapters.ps1, restarts all local network adapters search-filename.ps1, searches the directory tree for filenames by given pattern search-files.ps1, searches the given pattern in the given files scan-ports.ps1, scans the network for open/closed ports diff --git a/README.md b/README.md index 7df04818..b0bb0f30 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Mega Collection of PowerShell Scripts * [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer (needs admin rights) * [query-smart-data.ps1](Scripts/query-smart-data.ps1) - queries the S.M.A.R.T. data of your HDD/SSD's * [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer (needs admin rights) +* [restart-network-adapters.ps1](Scripts/restart-network-adapters.ps1) - restarts all local network adapters * [upgrade-ubuntu.ps1](Scripts/upgrade-ubuntu.ps1) - upgrades Ubuntu Linux to the latest (LTS) release * [wakeup.ps1](Scripts/wakeup.ps1) - sends a magic packet to the given computer, waking him up diff --git a/Scripts/restart-network-adapters.ps1 b/Scripts/restart-network-adapters.ps1 new file mode 100644 index 00000000..67cc3d97 --- /dev/null +++ b/Scripts/restart-network-adapters.ps1 @@ -0,0 +1,32 @@ +#Requires -RunAsAdministrator +<# +.SYNOPSIS + restart-network-adapters.ps1 +.DESCRIPTION + Restarts all local network adapters (needs admin rights) +.INPUTS + None +.OUTPUTS + None +.EXAMPLE + PS> .\restart-network-adapters.ps1 +.LINK + htts://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz + Creation Date: 2021-08-27 + License: CC0 +#> + +try { + $StopWatch = [system.diagnostics.stopwatch]::startNew() + + Get-NetAdapter | Restart-NetAdapter + + [int]$Elapsed = $StopWatch.Elapsed.TotalSeconds + "✔️ restarted all local network adapters in $Elapsed sec" + exit 0 +} catch { + write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +}