Forum Discussion
Rambo363636
Jul 19, 2024Brass Contributor
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" -Recurse | Remove-Item
Get-ChildItem -Path "%appdata%\Microsoft\usertemplates" -Filter "WordTemplate-2.dotx" -Recurse | Remove-Item
Could you please assist me providing a full powershell script that will work and remove the above files at above location on all the intune devices remotely.
Thanks.
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" } }
- sdtslmnBrass Contributor
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" } }
- Rambo363636Brass ContributorHi Sedat,
This worked. Thanks very much. Appreciate it🙂- sdtslmnBrass Contributoryou are welcome