ConfigMgr Log Sanitizer Powershell Script

Do you ever need to email or post ConfigMgr log files or snippets online for blogs or support? I know I do. I wanted to have a way to consistently clean log files quickly, so I wrote a small PowerShell script to help. It’s nothing special – the hardest part is figuring out which regular expressions work best for each data type you want to replace. I ended up with 4 regular expressions that work well for the smsts.log. Here are the 4 types and examples of log file entries before and after each regex:

  1. Server Name

    $regex.Add("ASD\w*-\w+","XXX-ServerName")
    Before: Successfully connected to MP ASD-CM01
    After: Successfully connected to MP XXX-ServerName
    SCCM Site Code

    $regex.Add("(CM1)","XXX")
    Before: Action command line: smsswd.exe /run:CM100123 ServiceUI.exe -process:TSProgressUI.exe C:\Windows\System32\cmd.exe
    After: Action command line: smsswd.exe /run:XXX00123 ServiceUI.exe -process:TSProgressUI.exe C:\Windows\System32\cmd.exe
    URLs with domain names

    $regex.Add("(CM1)","XXX")
    Before: Action command line: smsswd.exe /run:CM100123 ServiceUI.exe -process:TSProgressUI.exe C:\Windows\System32\cmd.exe
    After: Action command line: smsswd.exe /run:XXX00123 ServiceUI.exe -process:TSProgressUI.exe C:\Windows\System32\cmd.exe
    Specific words unique to your company

    $regex.Add("(SecretProductName|SecretProductName2)","XXXXXXXXX")
    Before: Parsing step node: 1.0 Launch SecretProductName1 UDI Wizard
    Parsing step node: 1.0 Launch XXXXXXXXX UDI Wizard
    #Be sure to test your regular expressions. There are several online test tools available.

I’ve added the file to my GitHub repository (first one yay!!) here: https://github.com/AdamGrossTX/PowershellScripts/blob/master/PSLogSanitizer.ps1.

Let me know if you have any suggestions for improvements.

You Might Also Like

No Comments

Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.