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 1 reply, has 2 voices, and was last updated by

 
Participant
3 years, 5 months ago.

  • Author
    Posts
  • #32855

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

    I have the following code, but I need to extract the "return code" string as well as whatever numerical value is there, either 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" from the string above.

    $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]!>

    Thank you all for your help.

  • #32861

    Participant
    Topics: 12
    Replies: 45
    Points: 0
    Rank: Member

    Example of use:

    Get-SCCMReturnCode "C:\Windows\ccmsetup\Logs\ccmsetup.log"
    Get-SCCMReturnCode -LogPath "C:\Windows\ccmsetup\Logs\ccmsetup.log"
    

    Here is this code:

    function Get-SCCMReturnCode {
    
    [CmdletBinding()]
    
        param(
            [parameter(Mandatory=$true, Position=0)][string]$LogPath
        )
    
        $string = "![LOG[CcmSetup is exiting with return code "
        $StringFound = Select-String -Path $LogPath -SimpleMatch $string
        if ($StringFound)
        {
            try
            {
                $ReturnCode = (($StringFound.ToString() -split "CcmSetup is exiting with ") | ? { $_ -like "*return code*" }).Split(']')[0]
            }
            catch
            {
                $ReturnCode = "Could not extract return code accurately from $($Stringfound.ToString())"
            }
        
        
        }
        else
        {
            $ReturnCode = "Not Found"
        }
        
        Write-Output $ReturnCode
    
    }
    

    Hope this helps.

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