# Define the base path for Revit settings in the AppData folder $basePath = "$env:APPDATA\Autodesk\Revit" # Get a list of directories for Revit versions $revitVersions = Get-ChildItem -Path $basePath -Directory | Where-Object { $_.Name -match "^Revit \d{4}$" } # Find the latest version of Revit $latestRevit = $revitVersions | Sort-Object Name -Descending | Select-Object -First 1 if ($latestRevit) { # Path to the latest Revit folder $latestRevitPath = $latestRevit.FullName Write-Output "Latest Revit Version Path: $latestRevitPath" # Path to the UIState.dat file $uiStateFilePath = Join-Path -Path $latestRevitPath -ChildPath "UIState.dat" if (Test-Path -Path $uiStateFilePath) { Write-Output "Found UIState.dat at: $uiStateFilePath" # Close Revit if it is running $revitProcess = Get-Process -Name "Revit" -ErrorAction SilentlyContinue if ($revitProcess) { Write-Output "Closing Revit..." Stop-Process -Id $revitProcess.Id -Force Start-Sleep -Seconds 5 # Wait a few seconds to ensure Revit is fully closed } else { Write-Output "Revit is not currently running." } # Rename the UIState.dat file $backupFilePath = "$uiStateFilePath.bak" Rename-Item -Path $uiStateFilePath -NewName $backupFilePath Write-Output "Renamed UIState.dat to UIState.dat.bak" # Relaunch Revit $revitExePath = "C:\Program Files\Autodesk\Revit $($latestRevit.Name.Substring(6))\Revit.exe" if (Test-Path -Path $revitExePath) { Write-Output "Relaunching Revit..." Start-Process -FilePath $revitExePath } else { Write-Output "Revit executable not found at: $revitExePath" } } else { Write-Output "UIState.dat file not found in the latest Revit version folder." } } else { Write-Output "No Revit version folders found in $basePath." }