Query about Intune Proactive Remediation Script Output in Device Status

Copper Contributor

Hello Everyone,

I’m using Intune’s Proactive Remediation and have a question. I’ve made a detection script and a remediation script. The remediation script works well and has an output message. But, when I check the device status in Intune, I only see the detection script’s output. For example, I want to show the size of the temp files removed by the remediation script.

Does anyone have a sample script that shows the remediation script’s output in the post-remediation detection output? How can I make the remediation script’s output visible in Intune’s device status post-remediation detection output? Any advice would be appreciated.

Thanks!

5 Replies
Did you enabled the other colums also as mentioned here:
https://call4cloud.nl/2021/05/the-laps-reloaded/#second-part
If you added the proper columns and you still don't get the output... maybe sharing the script could help :)
Yes I enabled the columns and and checked mentioned article as well.
I'm able to see the output in Intune but I only able to see the output from detection script in both the places (pre and post remediation detection output) not from remediation script.
This is a tricky one, but I think it is doable. As I see it, you will need to put in a condition in your detection script in such a way so that you are able to display the output in form of a value parsed dynamically to a variable. Something like -

$size = <Your detection script return's the size of the of the temp folder>

if ($size -gt 100) {
"Clean-up required"
exit 1
}
else {
"Temp folder is now at $size"
Exit 0
}
##################################DetectionScript################################
# Define the path
$Path = "C:\Test\Intune\NewFolder"

# Remediation results collection
$DetectionResults = @()

# Flag for failure
$FlagFailure = $false

# Check if the path exists
if(Test-Path -Path $Path){
$DetectionResults += "Path $Path exists."
Write-Output "Path $Path exists."
}else{
$DetectionResults += "Path $Path does not exist."
Write-Output "Path $Path does not exist."
$FlagFailure = $true
}
CLS
# Proactive remediation reporting and exit
if($FlagFailure -eq $true){
# One or more settings have failed
# Write output for PAR reporting
Write-Output -InputObject ($DetectionResults -join ', ')
Exit 1
}else{
# Setting are correct
# Write output for PAR reporting
Write-Output -InputObject ($DetectionResults -join ', ')
Exit 0
}

#####################################RemediationScript####################################################

# Define the path
$Path = "C:\Test\Intune"

# Remediation results collection
$RemediationResults = @()

# Flag for failure
$FlagFailure = $false

# Check if the path exists
if(Test-Path -Path $Path){
$RemediationResults += "Path $Path exists."
Write-Output "Path $Path exists."
}else{
$RemediationResults += "Path $Path does not exist."
Write-Output "Path $Path does not exist."
$FlagFailure = $true
}

# Create a new directory
$NewDir = New-Item -Path $Path -Name "NewFolder" -ItemType "directory" -ErrorAction SilentlyContinue

if($NewDir){
$RemediationResults += "Created new directory at $($NewDir.FullName)"
Write-Output "Created new directory at $($NewDir.FullName)"
}else{
$RemediationResults += "Failed to create new directory at $Path\NewFolder"
Write-Output "Failed to create new directory at $Path\NewFolder"
$FlagFailure = $true
}
CLS
# 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
}
Can you please check above script? There simply I'm checking the folder named "NewFolder" is present or not in specified directory. if not then returning exit code 1 and then in remediations script I'm creating the New folder named "NewFolder".
and once done with this I have added the output message in remediation script so that message I want to populate in Intune.