Forum Discussion
Raman220
Jan 10, 2024Copper Contributor
Query about Intune Proactive Remediation Script Output in Device Status
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. ...
rahuljindal
Jan 10, 2024Bronze Contributor
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
}
$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
}
- Raman220Jan 10, 2024Copper Contributor##################################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
}- Raman220Jan 10, 2024Copper ContributorCan 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.