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. ...
Raman220
Jan 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
}
# 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
}
Raman220
Jan 10, 2024Copper Contributor
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.
and once done with this I have added the output message in remediation script so that message I want to populate in Intune.