Run MSI from PowerShell script with spaces in directories

Make use of double “” to add a single ” in a variable for paths that has spaces

C:\Program Files (x86)\ThunderBolt 3 Update

$ExportPath = ${Env:ProgramFiles(x86)} + "\ThunderBolt 3 Update"
Write-Log "Detecting Thunderbolt Driver Version"
$TBTDriverVersion = (Get-WmiObject Win32_PnPSignedDriver | Where-Object { $_.DeviceName -like "*Thunderbolt(TM) Controller*" }).driverversion
	if ($null -eq $TBTDriverVersion) {
		try {
                    Write-Log "Thunderbolt Driver not found"
                    $InstallCmd = "$ExportPath\SW\$CSVCMDSW"
                    $InstallCmdLog = "/l*v ""$ExportPath\Install_SW.log"""
                    $InstallCmdComplete = "/i ""$InstallCmd"" /qn"

                    Write-Log "Installing Thunderbolt Software"
                    $InstallTBTSoftware = Start-Process -FilePath msiexec.exe -ArgumentList $InstallCmdComplete -Wait 
                }                
                catch {
                    Write-Log "Thunderbolt Software installation failed "$InstallTBTSoftware.ExitCode". Logs located at $ExportPath"
                    Write-Log "----------------------------- End Script ------------------------------"
                    Exit
                }

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *