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" -R...
- Jul 22, 2024
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" } }
sdtslmn
Jul 22, 2024MCT
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"
}
}- Rambo363636Jul 30, 2024Brass ContributorHi Sedat,
This worked. Thanks very much. Appreciate it🙂- sdtslmnJul 30, 2024MCTyou are welcome