GyroTwister
asked on
PowerShell | Parsing log file for certain line
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\ccmse tup.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.l og".
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:
I'm trying to monitor the process of uninstalling a SCCM client from a computer. Normally you should give the command "C:\Windows\ccmsetup\ccmse
However the uninstall process keeps track of its progress in a logfile which can be found here: "C:\Windows\ccmsetup\Logs\
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!")
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello all,
Thanks for the first pointers. It is still not working as I expect but with the provided solutions from you, I am testing a better script. Once it works I'll let you know.
Thanks for the first pointers. It is still not working as I expect but with the provided solutions from you, I am testing a better script. Once it works I'll let you know.
Let us know if you have any questions.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To get the status, you would need to be getting feedback from the uninstall process and then know how to interpret that feedback to give relevant status info. I'm not sure how to do that.
You could show the timestamp of when the uninstall started and that might be a good enough gauge to know how much time is left... ?
You could show the timestamp of when the uninstall started and that might be a good enough gauge to know how much time is left... ?
ASKER
-
$_ -match "\<\!\[LOG\[CcmSetup is exiting with return code 0\]LOG\]"
So the whole line would be:
Get-Content -Path $CCMLog -Tail 1 -Wait | Where {$_ -match "\<\!\[LOG\[CcmSetup is exiting with return code 0\]LOG\]"}
Also I redo some lines:
Open in new window