|
| 1 | +# Define the path to the MSI, the wrapped arguments, and the .NET installer script |
| 2 | +$msiPath = "$PSScriptRoot\CLIENT_{<YOURCOMPANY>.printix.net}_{<TENANTID>}.MSI" # REPLACE WITH YOUR PRINTIX MSI FROM SOFTWARE DROPDOWN IN PRINTIX ADMIN CONSOLE |
| 3 | +$wrappedArgs = "WRAPPED_ARGUMENTS=/id:<YOURTENANTID>" |
| 4 | +$dotNetInstaller = "$PSScriptRoot\install-dotnet.ps1" |
| 5 | + |
| 6 | +# Function to check if the script is running as administrator |
| 7 | +function Test-IsAdmin { |
| 8 | + $currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) |
| 9 | + return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 10 | +} |
| 11 | + |
| 12 | +# Restart script with elevated privileges if not already running as admin |
| 13 | +if (-not (Test-IsAdmin)) { |
| 14 | + Start-Process powershell "-File `"$PSCommandPath`"" -Verb RunAs |
| 15 | + exit |
| 16 | +} |
| 17 | + |
| 18 | +# Setup logging |
| 19 | +$logDirectory = "C:/IntuneLogs" |
| 20 | +$logFile = "$logDirectory/PrintixLog$(Get-Date -Format 'yyyyMMddHHmmss').txt" |
| 21 | + |
| 22 | +if (-not (Test-Path $logDirectory)) { |
| 23 | + New-Item -Path $logDirectory -ItemType Directory -Force | Out-Null |
| 24 | +} |
| 25 | + |
| 26 | +function Log-Message { |
| 27 | + param ( |
| 28 | + [string]$message |
| 29 | + ) |
| 30 | + Add-Content -Path $logFile -Value $message |
| 31 | +} |
| 32 | + |
| 33 | +# Define the registry path and value name |
| 34 | +$regPath = "HKLM:\SOFTWARE\printix.net\Printix Client\CurrentVersion" |
| 35 | +$parentRegPath = "HKLM:\SOFTWARE\printix.net" |
| 36 | + |
| 37 | +# Function to compare version numbers |
| 38 | +function Compare-Version { |
| 39 | + param ( |
| 40 | + [string]$v1, |
| 41 | + [string]$v2 |
| 42 | + ) |
| 43 | + $ver1 = [System.Version]$v1 |
| 44 | + $ver2 = [System.Version]$v2 |
| 45 | + return $ver1.CompareTo($ver2) |
| 46 | +} |
| 47 | + |
| 48 | +# Function to install Printix Client |
| 49 | +function Install-PrintixClient { |
| 50 | + param ( |
| 51 | + [string]$msiPath, |
| 52 | + [string]$wrappedArgs |
| 53 | + ) |
| 54 | + Log-Message "Installing Printix Client..." |
| 55 | + $installProcess = Start-Process msiexec.exe -ArgumentList "/i `"$msiPath`" $wrappedArgs /qn /norestart" -PassThru -Wait |
| 56 | + |
| 57 | + if ($installProcess.ExitCode -eq 0) { |
| 58 | + Log-Message "Printix Client installation completed successfully." |
| 59 | + Start-Sleep -Seconds 60 |
| 60 | + Log-Message "Printix Client installation script completed successfully." |
| 61 | + exit 0 |
| 62 | + } elseif ($installProcess.ExitCode -eq 1618) { |
| 63 | + Log-Message "Another installation is already in progress. Waiting before retrying..." |
| 64 | + Start-Sleep -Seconds 120 |
| 65 | + Install-PrintixClient -msiPath $msiPath -wrappedArgs $wrappedArgs |
| 66 | + } else { |
| 67 | + Log-Message "Printix Client installation failed with exit code $($installProcess.ExitCode)." |
| 68 | + exit $installProcess.ExitCode |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +# Check if any .NET Runtime 6 version is installed by looking for the specific folders |
| 73 | +function Check-DotNetRuntime { |
| 74 | + $dotnetFolders = @( |
| 75 | + "C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\", |
| 76 | + "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\", |
| 77 | + "C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\" |
| 78 | + ) |
| 79 | + |
| 80 | + foreach ($folder in $dotnetFolders) { |
| 81 | + if (-not (Get-ChildItem -Path $folder -Directory | Where-Object { $_.Name -like "6*" })) { |
| 82 | + Log-Message "Required .NET 6.x folder not found in: $folder" |
| 83 | + return $false |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + Log-Message ".NET Runtime 6.x is installed in all required folders." |
| 88 | + return $true |
| 89 | +} |
| 90 | + |
| 91 | +# Function to install .NET Runtimes |
| 92 | +function Install-DotNetRuntimes { |
| 93 | + $dotnetInstallScript = "$dotNetInstaller" |
| 94 | + |
| 95 | + if (-not (Test-Path $dotnetInstallScript)) { |
| 96 | + Log-Message "The dotnet-install.ps1 script was not found." |
| 97 | + exit 1 |
| 98 | + } |
| 99 | + |
| 100 | + Log-Message "Installing .NET Desktop Runtime 6.0.32..." |
| 101 | + & powershell -File $dotnetInstallScript -Runtime windowsdesktop -Channel 6.0 -Version 6.0.32 |
| 102 | + Log-Message ".NET Desktop Runtime 6.0.32 installation completed." |
| 103 | + |
| 104 | + Log-Message "Installing .NET ASP.NET Core Runtime 6.0.32..." |
| 105 | + & powershell -File $dotnetInstallScript -Runtime aspnetcore -Channel 6.0 -Version 6.0.32 |
| 106 | + Log-Message ".NET ASP.NET Core Runtime 6.0.32 installation completed." |
| 107 | + |
| 108 | + # Update PATH globally |
| 109 | + $dotnetPath = "C:\Program Files\dotnet" |
| 110 | + $existingPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine") |
| 111 | + |
| 112 | + if ($existingPath -notlike "*$dotnetPath*") { |
| 113 | + [System.Environment]::SetEnvironmentVariable("Path", "$existingPath;$dotnetPath", "Machine") |
| 114 | + Log-Message "PATH environment variable updated to include $dotnetPath." |
| 115 | + |
| 116 | + # Refresh the current session to recognize the updated PATH |
| 117 | + $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") |
| 118 | + } else { |
| 119 | + Log-Message "PATH environment variable already includes $dotnetPath." |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +# Main logic |
| 124 | +if (Check-DotNetRuntime) { |
| 125 | + Log-Message ".NET Runtime 6.x is already installed in all required folders." |
| 126 | +} else { |
| 127 | + Install-DotNetRuntimes |
| 128 | +} |
| 129 | + |
| 130 | +# Proceed with Printix installation only if .NET Runtime is confirmed to be present in all required folders |
| 131 | +if (Check-DotNetRuntime) { |
| 132 | + # Check if the full registry entry exists |
| 133 | + if (Test-Path $regPath) { |
| 134 | + $currentVersion = (Get-ItemProperty -Path $regPath -Name "CurrentVersion").CurrentVersion |
| 135 | + $minVersion = "2.3.0.211" |
| 136 | + $comparison = Compare-Version $currentVersion $minVersion |
| 137 | + |
| 138 | + if ($comparison -lt 0) { |
| 139 | + $uninstallerPath = "C:\Program Files\printix.net\Printix Client\unins000.exe" |
| 140 | + if (Test-Path $uninstallerPath) { |
| 141 | + Log-Message "Uninstalling existing Printix Client version $currentVersion..." |
| 142 | + Start-Process -FilePath $uninstallerPath -ArgumentList "/verysilent" -Wait |
| 143 | + Log-Message "Printix Client uninstalled successfully." |
| 144 | + } |
| 145 | + |
| 146 | + Install-PrintixClient -msiPath $msiPath -wrappedArgs $wrappedArgs |
| 147 | + } elseif ($comparison -ge 0) { |
| 148 | + Log-Message "Current Printix Client version ($currentVersion) is up-to-date. No action required." |
| 149 | + exit 0 |
| 150 | + } |
| 151 | + } else { |
| 152 | + if (Test-Path $parentRegPath) { |
| 153 | + Log-Message "Printix would be installed." |
| 154 | + Install-PrintixClient -msiPath $msiPath -wrappedArgs $wrappedArgs |
| 155 | + } else { |
| 156 | + Log-Message "Registry path $parentRegPath does not exist. Installing Printix Client." |
| 157 | + Install-PrintixClient -msiPath $msiPath -wrappedArgs $wrappedArgs |
| 158 | + } |
| 159 | + } |
| 160 | +} else { |
| 161 | + Log-Message "Skipping Printix Client installation due to missing .NET Runtime 6 in one or more required folders." |
| 162 | + exit 0 |
| 163 | +} |
0 commit comments