From 5d74cbb92fee9ace5d9d2e8a80251415be65004f Mon Sep 17 00:00:00 2001 From: David Yoder Date: Thu, 18 Aug 2022 18:19:45 -0400 Subject: [PATCH] initial commit --- Remove-OldRevitLocals.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Remove-OldRevitLocals.ps1 diff --git a/Remove-OldRevitLocals.ps1 b/Remove-OldRevitLocals.ps1 new file mode 100644 index 0000000..225d8a7 --- /dev/null +++ b/Remove-OldRevitLocals.ps1 @@ -0,0 +1,27 @@ +# Set the maximum allowed age of Revit local files +$FileAllowedAge = (Get-Date).AddMonths(-1) + +# Build all Revit local paths +$RevitLocalPaths = @() +ForEach ( $userProfile in (Get-ChildItem -Path "${Env:SystemDrive}\Users" | Where-Object { $_.PSIsContainer }) ) { + If ( Test-Path "${userProfile}\Documents" ) { $RevitLocalPaths.Add("${userProfile}\Documents") } + If ( Test-Path "${userProfile}\Documents\Revit Locals" ) { $RevitLocalPaths.Add("${userProfile}\Documents\Revit Locals") } +} + +ForEach ( $path in $RevitLocalPaths ) { + $RevitFiles = Get-ChildItem -Path "${path}\*.*" -Filter '*.rvt' | Where-Object {$_.LastWriteTime -lt $FileAllowedAge} + If ( $RevitFiles ) { + ForEach ($revitfile in $RevitFiles) { + + $parentDir = $revitfile.DirectoryName + $baseName = $revitfile.BaseName + $BackupDir = "${parentDir}\${basename}_backup" + + If ( (Test-Path "${revitfile}") -and (Test-Path "${BackupDir}")) { + LogMsg "Deleting ""${revitfile}"" and backup directory ""${BackupDir}""" + Remove-Item "${revitfile}" -Force -ErrorAction SilentlyContinue + Remove-Item "${BackupDir}" -Recurse -ErrorAction SilentlyContinue + } + } + } +} \ No newline at end of file