Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


xpd

xpd

Geek @ Coastguard NZ
13659 posts

Uber Geek

Retired Mod
ID Verified
Trusted
Lifetime subscriber

#296143 25-May-2022 07:22
Send private message

Just throwing around an idea for something that could come in handy at work at times, need some other views / input etc.... 

 

 

 

I want to be able to have a script sitting on a network drive that users can access, that will run a Windows command, save the output to a txt file, then email that txt file to me with some sort of identifier of the user.

 

Example : Bob runs script which runs a ping test and outputs to myping.txt then emails myping.txt to mypingtest@xpd which appears to be from bob@xpd

 

 

 

My main issue is the identifier - as I'm typing this, Im thinking Powershell might be able to do this for me, make a call to obtain the logged in users name and attach that somewhere to the txt file or email.......

 

 

 

Overall it needs to run without any other requirements, any Windows install must be able to run it.....

 

 





       Gavin / xpd / FastRaccoon / Geek of Coastguard New Zealand

 

                      LinkTree -   kiwiblast.co.nz - Lego and more

 

       Support Kiwi music!   The People   Black Smoke Trigger   Like A Storm   Devilskin

 

                                            NZ GEEKS Discord______________________________

 

 


Create new topic
bagheera
531 posts

Ultimate Geek


  #2918240 25-May-2022 08:22
Send private message

power shell the way to go, and use the dos variable %USERNAME%@xpd will use the logged-in user - as long as it is not like default user or admin, if it is then variable %COMPUTERNAME% would be a better one to use.

 

 

 

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.2

 

 

 

so

 

$user = $Env:USERNAME

 

$computer = $Env:COMPUTERNAME

 

 

 

would get you the user & computer name for the powershell


 
 
 

Trade NZ and US shares and funds with Sharesies (affiliate link).
SirHumphreyAppleby
2819 posts

Uber Geek


  #2918256 25-May-2022 09:37
Send private message

Easy to do with a batch file or PowerShell. I use CMail to send the actual e-mail (must be somewhere in the PATH or in the same directory as the script), but it can be done directly from within PowerShell, it's just more work.

 

When running a batch command, the username is available in the %username% environment variable. If you type 'set' on the command prompt you will see a list of common variables in the usual environment, such as the computer name.

 

At its simplest, you could just do this...

 

ping_command > myping.txt
cmail -host:mail.example.com -to:mypingtest@xpd -from:%username%@xpd -a:myping.txt
del myping.txt

 

If you want the results in the message body, it's even simpler...

 

ping_command | cmail -host:mail.example.com -to:mypingtest@xpd -from:%username%@xpd --

 

Note, I am biased since I wrote CMail. Older builds will run on Windows versions as old as NT 4. Newer builds require Vista due to LibreSSL dropping support for older platforms.


Lias
5566 posts

Uber Geek

ID Verified
Trusted
Lifetime subscriber

  #2918270 25-May-2022 10:06
Send private message

Something like this should work:

 

 

$To = "xpd@work.com"
$From = "noreply@work.com"
$Server = "smtp.work.com"

 

$Ping = Test-NetConnection www.google.com

 

$Subject = "Test from $($env:COMPUTERNAME) at $(Get-Date)"
$Body = "Dear $To`r`n"
$Body = $Body + "`r`n"
$Body = $Body + "This is a test email sent from $($env:COMPUTERNAME) at $(Get-Date)`r`n"
$Body = $Body + "`r`n"
$Body = $Body + "It was sent via the following SMTP server: $Server`r`n"
$Body = $Body + "`r`n"
$Body = $Body + "Results`r`n"
$Body = $Body + "Ping Target: " + $Ping.ComputerName + "`r`n"
$Body = $Body + "Ping Address: " + $Ping.RemoteAddress + "`r`n"
$Body = $Body + "Ping Succeeded:" + $Ping.PingSucceeded + "`r`n"
$Body = $Body + "Ping RoundTripTime: " + $ping.PingReplyDetails.RoundtripTime + "`r`n"
$Body = $Body + "`r`n"

 

Send-MailMessage -Body $Body -Subject $Subject -To $To -From $From -SmtpServer $Server

 





I'm a geek, a gamer, a dad, a Quic user, and an IT Professional. I have a full rack home lab, size 15 feet, an epic beard and Asperger's. I'm a bit of a Cypherpunk, who believes information wants to be free and the Net interprets censorship as damage and routes around it. If you use my Quic signup you can also use the code R570394EKGIZ8 for free setup.


Create new topic





News and reviews »

Synology DS925+ Review
Posted 23-Apr-2025 15:00


Synology Announces DiskStation DS925+ and DX525 Expansion Unit
Posted 23-Apr-2025 10:34


JBL Tour Pro 3 Review
Posted 22-Apr-2025 16:56


Samsung 9100 Pro NVMe SSD Review
Posted 11-Apr-2025 13:11


Motorola Announces New Mid-tier Phones moto g05 and g15
Posted 4-Apr-2025 00:00


SoftMaker Releases Free PDF editor FreePDF 2025
Posted 3-Apr-2025 15:26


Moto G85 5G Review
Posted 30-Mar-2025 11:53


Ring Launches New AI-Powered Smart Video Search
Posted 27-Mar-2025 16:30


OPPO RENO13 Series Launches in New Zealand
Posted 27-Mar-2025 05:00


Sony Electronics Announces the WF-C710N Truly Wireless Noise Cancelling Earbuds
Posted 26-Mar-2025 20:37


New Harman Kardon Portable Home Speakers Bring Performance and Looks Together
Posted 26-Mar-2025 20:30


Data Insight Launches The Data Academy
Posted 26-Mar-2025 20:21


Oclean AirPump A10 Portable Water Flosser Wins iF Design Award 2025
Posted 20-Mar-2025 12:05


OPPO Find X8 Pro Review
Posted 14-Mar-2025 14:59


Samsung Galaxy Ring Now Available in New Zealand
Posted 14-Mar-2025 13:52









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.