Need to extract SCCM client install return code from ccmsetup.log file

Welcome Forums General PowerShell Q&A Need to extract SCCM client install return code from ccmsetup.log file

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 5 months ago.

  • Author
    Posts
  • #32857

    Participant
    Topics: 42
    Replies: 77
    Points: 26
    Rank: Member

    I have the following code, but I need to extract the "return code" string as well as whatever numerical value is there, for instance a "0", or a 1", etc.

    I have no idea how to do this.

    Here is what I have so far and it works great, but I just want to extract "return code 0", or "return code 1".


    $SCCMClntReturnCode = @(
    Get-Content -Path "C:\Windows\ccmsetup\Logs\ccmsetup.log" |
    Select-Object -Last 1
    )

    Here is the actual string that I would like to extract from:

    ![LOG[CcmSetup is exiting with return code 0]LOG]!

    So as you can see from this string it shows the "return code" string along with the exit code value. All I am looking to extract is just that and leave out everything else and this is where I am stuck.

    Thank you all for your help.

  • #32859

    Participant
    Topics: 2
    Replies: 19
    Points: 1
    Rank: Member

    Being a scripting newbie I might be missing something, but I would just use the replace method.
    Something like:

     
    $rstring1 = "![LOG[CcmSetup is exiting with "
    $rstring2 = "]LOG]!"
    $SCCMClntReturnCode.Replace($rstring1,"").Replace($rstring2,"")
    
  • #32860

    Participant
    Topics: 42
    Replies: 77
    Points: 26
    Rank: Member

    Thanks, but I already researched this a bit more and I came up with the following that works perfectly for my need:


    $SCCMClntReturnCode = @(
    Get-Content -Path "C:\Windows\ccmsetup\Logs\ccmsetup.log" |
    Select-Object -Last 1
    )

    $RegEx = [regex] "\[([a-zA-Z0-9-\s]+)\]"
    $Match = $RegEx.match("$SCCMClntReturnCode")
    $Text = $Match.groups[1].value
    $String = $Text.Replace('CcmSetup is exiting with return code ', '')

The topic ‘Need to extract SCCM client install return code from ccmsetup.log file’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort