This script monitors network bandwidth usage over time, capturing utilization data for a specified duration. This is useful for observing patterns in bandwidth usage.
# Define network adapter and monitoring duration
$networkAdapter = "Ethernet" # Change to match your adapter name
$duration = 60 # Duration in seconds
$interval = 5 # Interval between measurements
$endTime = (Get-Date).AddSeconds($duration)
while ((Get-Date) -lt $endTime) {
$bytesSent = (Get-Counter "\Network Interface($networkAdapter)\Bytes Sent/sec").CounterSamples[0].CookedValue
$bytesReceived = (Get-Counter "\Network Interface($networkAdapter)\Bytes Received/sec").CounterSamples[0].CookedValue
Write-Output "$(Get-Date): Sent = $([math]::Round($bytesSent / 1024, 2)) KBps, Received = $([math]::Round($bytesReceived / 1024, 2)) KBps"
Start-Sleep -Seconds $interval
}
• Modify $networkAdapter, $duration, and $interval as needed.
• Explanation: This script monitors and logs bandwidth usage every few seconds over a specified period.