Blending PowerShell and Windows Commands

Recently I had a requirement to obtain tracert (traceroute) information for all of my ConfigMgr 2012 servers. Here’s a quick (and crude) example of how to capture tracert information for each system, and then write the info to its own file for each server.

Systems.txt is a file that has each system listed, one per line. gc is the alias for get-content. We then run a foreach loop to run tracert on each system, capturing the value into $a, then display the output, as well as pipe it to a file.


gc .\systems.txt | % { $a = tracert $_; $a; $a>@($_ + ".txt")}

Happy scripting!

Greg

About Greg Ramsey
Greg Ramsey is a Distinguished Engineer for Dell Digital - Services. He has a B.S. in Computer Sciences and Engineering from The Ohio State University and has co-authored many books over the years. Greg is also a board member of the Northwest System Center User Group and the Midwest Management Summit. ​Greg has been a Microsoft Endpoint Manager (ConfigMgr, Intune) MVP for over 14 years.

2 Responses to Blending PowerShell and Windows Commands

  1. Aleksandar says:

    gc .\servers.txt | % { tracert $_ | tee -var a; $a>@($_ + “.txt”)}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: