Youssef Heiba Posted November 2, 2023 Posted November 2, 2023 Hello Everyone ! I could find a script that is going to show the internet speed for end-users through Powershell. You can use the follow script to also send an automated email with the results : #https://www.speedtest.net/apps/cli cls $DownloadURL = "https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-win64.zip" #location to save on the computer. Path must exist or it will error $DOwnloadPath = "c:\temp\SpeedTest.Zip" $ExtractToPath = "c:\temp\SpeedTest" $SpeedTestEXEPath = "C:\temp\SpeedTest\speedtest.exe" #Log File Path $LogPath = 'c:\temp\SpeedTestLog.txt' #Start Logging to a Text File $ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null $ErrorActionPreference = "Continue" Start-Transcript -path $LogPath -Append:$false #check for and delete existing log files function RunTest() { $test = & $SpeedTestEXEPath --accept-license $test } function sendMail ($subject, $message) { "Sending Email" #SMTP server name $smtpServer = "smtp.office365.com" $EmailSender = "noreply@yourdomain.com" $emailPassword = "password123_or_monkey" $port = '587' $from = "noreply@yourdomain.com" $to = "you@yourdomain.com" #Creating a Mail object $msg = new-object Net.Mail.MailMessage $emailCredential = New-Object System.Net.NetworkCredential($EmailSender, $emailPassword) #Creating SMTP server object $smtp = new-object Net.Mail.SmtpClient($smtpServer) $smtp.Port = $port $smtp.EnableSSl = $true $smtp.Credentials = $emailCredential #Email structure $msg.From = $from $msg.To.add($to) $msg.subject = $subject $msg.body = $message #Sending email $smtp.Send($msg) write-host "Email Sent" -ForegroundColor Green }; #check if file exists if (Test-Path $SpeedTestEXEPath -PathType leaf) { Write-Host "SpeedTest EXE Exists, starting test" -ForegroundColor Green RunTest } else { Write-Host "SpeedTest EXE Doesn't Exist, starting file download" #downloads the file from the URL wget $DownloadURL -outfile $DOwnloadPath #Unzip the file Add-Type -AssemblyName System.IO.Compression.FileSystem function Unzip { param([string]$zipfile, [string]$outpath) [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) } Unzip $DOwnloadPath $ExtractToPath RunTest } #get hostname $Hostname = hostname #read results out of log file into string $MailMessage = (Get-Content -Path $LogPath) -join "`n" #email results use log file string as body $MailSubject = $Hostname + " SpeedTest Results" sendMail $MailSubject $MailMessage #stop logging Stop-Transcript
Administrators Anne Posted November 3, 2023 Administrators Posted November 3, 2023 Hey Yousef, Thanks for sharing this, Can I ask if you are in our Discord channel? as we also have a automation/scripting channel thee where scripts like this would be super useful. You can check it out here
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now