Forum Discussion

monkeybradders's avatar
monkeybradders
Copper Contributor
Jan 15, 2025

help with remediation

Hi, i'm trying to create detection and remediation scripts for intune to detect the presence of a template in the users word startup folder 

**My detection is as follows**
$path = "C:\Users\$env:USERNAME\AppData\Roaming\Microsoft\Word\Startup\ACS Template 2010 2013 2016 (2) (1).dotm"
if (Test-Path $path) {
    Write-Output "File exists: $path"
    exit 1  # Success, file exists
} else {
    Write-Output "File not found: $path"
    exit 0  # Failure, file does not exist


**My remediation**
$path = "C:\Users\$env:USERNAME\AppData\Roaming\Microsoft\Word\Startup\ACS Template 2010 2013 2016 (2) (1).dotm" 
if (Test-Path $path) {
    Remove-Item -Path $path -Force


It seems like the detection works as the detection status is "without issues" but the remediation doesn't run. 

Any advice on how to correct this very much welcomed

  • jstrong013's avatar
    jstrong013
    Copper Contributor

    Based off of very quick and brief glance, I think you need to update your code: 

    if ( (Test-Path $path )-eq $true ) {
      Write-Output "File exists: $path"
      exit 1
    }
    
    ## My Remediation 
    if ( (Test-Path $path) -eq $true ) {
    	Remove-Item -Path $path -Force
    }

     

  • Lo-Tech's avatar
    Lo-Tech
    Copper Contributor

    Are you able to test your detection script and remediation scripts on a test PC or server?

    The detection script should return the exit code 1 and then that what triggers the remediation script.

    Remediations | Microsoft Learn

Resources