Blending PowerShell and Windows Commands
November 3, 2012 2 Comments
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
gc .\servers.txt | % { tracert $_ | tee -var a; $a>@($_ + “.txt”)}
Thanks Aleksandar! I need to use tee more often!