Forum Discussion

Rambo363636's avatar
Rambo363636
Brass Contributor
Jul 19, 2024
Solved

Need a powershell script to delete a word document on intune devices

Hi All,   I am trying to delete a word document on all intune devices. I have tried below but did not work. Get-ChildItem -Path "%appdata%\Microsoft\usertemplates" -Filter "WordTemplate-2.dotm" -R...
  • sdtslmn's avatar
    Jul 22, 2024

    Rambo363636 

     

    hope the following works for you 

     

    # Define the file paths and file names
    $templatePath = "$env:APPDATA\Microsoft\usertemplates"
    $templateFiles = @("WordTemplate-2.dotm", "WordTemplate-2.dotx")
    
    # Loop through each file and attempt to delete it
    foreach ($file in $templateFiles) {
        $fullPath = Join-Path -Path $templatePath -ChildPath $file
        if (Test-Path -Path $fullPath) {
            Remove-Item -Path $fullPath -Force -ErrorAction SilentlyContinue
            Write-Host "Deleted: $fullPath"
        } 
    }

Resources