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

Removing Empty Folders

There’s a “feature” in ConfigMgr 2012 that occurs when you perform the following steps:

  • Send a package to the DP
  • Enable the “Copy the content in this package to a package share on distribution points” checkbox.
  • Clear the “Copy the content in this package to a package share on distribution points” checkbox.

When you clear the checkbox, the contents of the folder on the share are removed, but the root folder (which is named by PackageID) remains.

Normally this wouldn’t be a problem, but we do have a 3rd party integration  to ConfigMgr 2012 that will look for packages on the package share, and since these are empty, we receive unexpected results.  As a result, here’s a simple PowerShell script to remove any empty folders from the smspkgd$ share:


get-childitem d:\smspkgd$  | % { if ((get-childitem -path $_.FullName -recurse | measure-object -property length -sum).sum -eq $null) {$_.Name; remove-item -path $_.FullName}}

Happy Scripting!