troubleshooting Question

PowerShell | Parsing log file for certain line

Avatar of GyroTwister
GyroTwisterFlag for Netherlands asked on
7 Comments2 Solutions463 ViewsLast Modified:
Hallo all,

I'm trying to monitor the process of uninstalling a SCCM client from a computer. Normally you should give the command "C:\Windows\ccmsetup\ccmsetup.exe /uninstall" and wait for it.

However the uninstall process keeps track of its progress in a logfile which can be found here: "C:\Windows\ccmsetup\Logs\ccmsetup.log".

When the uninstall is completed the last line of the logfile should start with: "<![LOG[CcmSetup is exiting with return code 0]LOG]". Here after there is more information displayed however that is not needed the determine the uninstall has completed successfully.

I seem unable to catch the last line and stop the job and go on with the other steps of uninstalling. Anyone any ideas? This is my code so far:
$SCCMUninstall = "C:\Windows\ccmsetup\ccmsetup.exe /uninstall"
$CCMLog = "C:\Windows\ccmsetup\Logs\ccmsetup.log"

Start-Job $SCCMUninstall

While (! (Test-Path $CCMLog)) {Sleep -Seconds 10}

Write-Host ("Monitoring " + $CCMLog)

Get-Content -Path $CCMLog -Tail 1 -Wait | Where {$_ -like "*<![LOG[CcmSetup is exiting with return code 0]LOG]*"}

Write-Host ("SCCM Client succesfully uninstalled!")
Senior Windows Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros