<#
.TITLE: Download and Execute Autodesk Custom Installer Setup File
.SYNOPSIS
Installs Autodesk software only if missing, with recovery logic for failed deployments.
.DESCRIPTION
Checks for existing installation first. If installed, returns version and exits.
If missing, checks for an existing deployment BAT file, otherwise downloads and runs installer.
.NOTES
Required Action1 Permissions:
- Run as System/Admin
- File System Access
- Process Termination
.PARAMETERS ( name || type || example )
- DownloadUrl || String || https://www.simplehttphost.com/RVT_2026-4.exe
- DeployPath || String || C:\Autodesk\RVT_2026-4
- ProgramName || String || Autodesk Revit 2026
#>
$ProgressPreference = 'SilentlyContinue'
#================================
# Logging Function
#================================
function Write-Log {
param (
[string]$Message,
[string]$Level = "INFO"
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Write-Host "[$timestamp] [$Level] $Message"
}
#================================
# Parameter Validation
#================================
foreach ($param in @("DownloadUrl","DeployPath","ProgramName")) {
if ([string]::IsNullOrWhiteSpace((Get-Variable $param -ValueOnly))) {
Write-Log "$param parameter is required" "ERROR"
exit 1
}
}
#================================
# Check if Program Is Installed
#================================
try {
Write-Log "Checking if $ProgramName is already installed"
$uninstallKeys = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$installedApp = Get-ItemProperty $uninstallKeys -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -like "*$ProgramName*" } |
Select-Object -First 1
if ($installedApp) {
Write-Log "$ProgramName is already installed"
Write-Log "Installed version: $($installedApp.DisplayVersion)"
Write-Log "No further action required. Exiting."
exit 0
}
Write-Log "$ProgramName not detected. Continuing installation workflow."
}
catch {
Write-Log "Failed during installation detection: $($_.Exception.Message)" "ERROR"
exit 1
}
#================================
# Check for Existing BAT Installer
#================================
try {
Write-Log "Checking for existing deployment BAT file in $DeployPath"
if (Test-Path $DeployPath) {
$batFile = Get-ChildItem -Path $DeployPath -Filter *.bat -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($batFile) {
Write-Log "Found deployment BAT file: $($batFile.FullName)"
Write-Log "Stopping Autodesk deployment processes"
Get-Process -Name "AdOdisDeployTool" -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 5
Write-Log "Executing deployment BAT file"
Start-Process -FilePath $batFile.FullName -WindowStyle Hidden
exit 0
}
}
Write-Log "No deployment BAT file found"
}
catch {
Write-Log "BAT file handling failed: $($_.Exception.Message)" "ERROR"
exit 1
}
#================================
# Resolve Paths
#================================
$ExeName = Split-Path $DownloadUrl -Leaf
$TargetDir = Split-Path $DeployPath -Parent
$ExePath = Join-Path $TargetDir $ExeName
#================================
# Ensure Target Directory Exists
#================================
try {
if (-not (Test-Path $TargetDir)) {
Write-Log "Creating directory $TargetDir"
New-Item -Path $TargetDir -ItemType Directory -Force | Out-Null
}
}
catch {
Write-Log "Failed to prepare target directory: $($_.Exception.Message)" "ERROR"
exit 1
}
#================================
# Download Installer if Missing
#================================
try {
if (-not (Test-Path $ExePath)) {
Write-Log "Downloading installer from $DownloadUrl"
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ExePath -UseBasicParsing
if (-not (Test-Path $ExePath)) {
throw "Installer download failed"
}
}
else {
Write-Log "Installer already exists"
}
}
catch {
Write-Log "Download failed: $($_.Exception.Message)" "ERROR"
exit 1
}
#================================
# Kill Autodesk ODIS Deployment Processes
#================================
try {
Write-Log "Stopping Autodesk deployment processes"
Get-Process -Name "AdOdisDeployTool" -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 5
}
catch {
Write-Log "Failed while stopping Autodesk processes: $($_.Exception.Message)" "ERROR"
exit 1
}
#================================
# Execute Installer
#================================
try {
Write-Log "Launching installer"
Start-Process -FilePath $ExePath -WindowStyle Hidden
}
catch {
Write-Log "Failed to start installer: $($_.Exception.Message)" "ERROR"
exit 1
}
Write-Log "Script completed successfully"
exit 0