Query about Intune Proactive Remediation Script Output in Device Status

Swahela Mulla 95 Reputation points
2024-01-05T15:09:07.64+00:00

Hello Everyone,

I've been working with Intune's Proactive Remediation and noticed a discrepancy in the device status display. Specifically, I would like to showcase the output of my remediation script in the post-remediation detection output.

I've successfully created a detection script and a remediation script. The remediation script is performing as per my requirement and also, I have added the output message. However, when checking the device status in Intune, I only see the output from detection script in both the places (pre and post remediation output).

e.g.: I have removed the temp files with the help of remediation script and want to showcase the removed files size.

Does anyone have sample script that reflecting the post-remediation detection output from remediation script?

Is there a way to ensure that the output from my remediation script is visible in the post-remediation detection output in Intune device status? Any insights or guidance on this would be greatly appreciated.

 

Thanks,

Swahela Mulla

 

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Intune | Other
0 comments No comments
{count} votes

Accepted answer
  1. Nick Eckermann 606 Reputation points
    2024-01-05T20:28:15.37+00:00

    When needing to get multiple outputs into the reporting we use something like this.

    Create as much data and keep adding it to $RemediationResults

    You will have to make up the logic to get a failure or not failure state we just use a variable flag to tag and exit accordingly.

    
    # Get each adapter we want to modify
    $NetworkAdapters = Get-NetAdapter | Where-Object {($_.InterfaceDescription -like "*Intel(R) Wi-Fi 6 AX201 160MHz*") -or ($_.InterfaceDescription -like "*Realtek USB GbE Family Controller*")}
    
    # Remediation results collection
    $RemediationResults = @()
    
    #Reset $FlagFailure
    $FlagFailure = $false
    
    #Loop through adapters to see if they have their DNS server address set correctly
    foreach($NetworkAdapter in $NetworkAdapters){
        # Get current DNS name servers
        $CurrentDNSNameServers = (Get-DnsClientServerAddress -InterfaceIndex $NetworkAdapter.InterfaceIndex -ErrorAction SilentlyContinue).ServerAddresses
        if($CurrentDNSNameServers){
            # Check for correct DNS name servers
            if(($CurrentDNSNameServers[0] -eq "1.1.1.1") -and ($CurrentDNSNameServers[1] -eq "149.112.112.112")){
                $RemediationResults += "DNS name servers set correctly on adapter $($NetworkAdapter.InterfaceDescription)"
                Write-Log -Message "DNS name servers set correctly on adapter $($NetworkAdapter.InterfaceDescription)" -Type Informational
            }else{
                # Set DNS name servers if not correct
                $RemediationResults += "DNS name servers not set correctly on adapter $($NetworkAdapter.InterfaceDescription)"
                Write-Log -Message "DNS name servers not set correctly on adapter $($NetworkAdapter.InterfaceDescription)" -Type Warning
                $RemediationResults += "Changing DNS name servers to 1.1.1.1 and 149.112.112.112 on adapter $($NetworkAdapter.InterfaceDescription)"
                Write-Log -Message "Changing DNS name servers to 1.1.1.1 and 149.112.112.112 on adapter $($NetworkAdapter.InterfaceDescription)" -Type Informational
                Set-DnsClientServerAddress -InterfaceIndex $NetworkAdapter.InterfaceIndex -ServerAddresses ("1.1.1.1", "149.112.112.112")
                
                # Check for correct DNS name servers
                $CurrentDNSNameServers = (Get-DnsClientServerAddress -InterfaceIndex $NetworkAdapter.InterfaceIndex -ErrorAction SilentlyContinue).ServerAddresses
                if(($CurrentDNSNameServers[0] -eq "1.1.1.1") -and ($CurrentDNSNameServers[1] -eq "149.112.112.112")){
                $RemediationResults += "DNS name servers set correctly on adapter $($NetworkAdapter.InterfaceDescription)"
                Write-Log -Message "DNS name servers set correctly on adapter $($NetworkAdapter.InterfaceDescription)" -Type Informational
                }else{
                    $RemediationResults += "Failed to set DNS name servers correctly on adapter $($NetworkAdapter.InterfaceDescription)"
                    Write-Log -Message "Failed to set DNS name servers correctly on adapter $($NetworkAdapter.InterfaceDescription)" -Type Error 
                    $FlagFailure = $true
                }
            }
        }
        $CurrentDNSNameServers = $null
    }
    
    # Proactive remediation reporting and exit
    if($FlagFailure -eq $true){
        # One or more settings have failed
        # Write output for PAR reporting
        Write-Output -InputObject ($RemediationResults -join ', ')
        Exit 1
    }else{
        # Setting are correct
        # Write output for PAR reporting
        Write-Output -InputObject ($RemediationResults -join ', ')
        Exit 0
    }
    

1 additional answer

Sort by: Most helpful
  1. Nick Eckermann 606 Reputation points
    2024-01-05T20:33:00.4033333+00:00

    This was a duplicate post

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.