Hi all,
I am working on a powershell script that runs an .msp install patch quietly across my IT environment. There is logic in the PowerShell script that verifies if office is x86 or x64 to apply the correct patch files, though this is a bit of a "lazy hack" because I am simply reading the Outlook regkey bitness.
The problem I am having, is that when I run the script on test machines, the script runs, but the if statements do not seem to be called. everything in the code runs up until the the step: "LogWrite ("verifying office 2016 version")" at that point, nothing else runs until the step "Logwrite("Installation Ended: $TStamp")"
I am wondering if there is a weird linebreak in the script but checks I have done on the Syntax showed nothing. for reference, I script in VS Code 1.38.0 on Powershell 5.1. Apologies in advance on the layout of the script as well, I also code in AutoIt and Python and sometimes my bracket positioning can cross contaminate between the languages. If I run the Start-Process line by itself, the command works, so I am wondering if it's something I am just not seeing.
Code below;
$Logfile = "C:\WinPatches.log" Function LogWrite { Param ([string]$logstring) Add-content $Logfile -value $logstring } <#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------#><#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------#><# Capture the PC name for the log file#> LogWrite("PC Name is: $Env:COMPUTERNAME")<# Creating a Time Variable#> $TStamp = Get-Date<# Copying all extracted patches locally..#> #Copy-Item $PSScriptRoot'\KB3085368x86' -Destination $Env:SystemDrive\temp -Recurse #Copy-Item $PSScriptRoot'\KB3085368x64' -Destination $Env:SystemDrive\temp -Recurse #Copy-Item $PSScriptRoot'\KB4484198x64' -Destination $Env:SystemDrive\temp -Recurse #Copy-Item $PSScriptRoot'\KB4484198x86' -Destination $Env:SystemDrive\temp -Recurse <#OFFICE 2016 - Bitness Variable#> LogWrite ("Checking RegKey Parameters") $Key = "HKLM:\Software\Microsoft\Office\16.0\Outlook" $Office2016 = (Get-ItemProperty -Path $Key).Bitness #Added log write below to confirm that the script is reading the registry properly. If it gives no value to the log, then it did not read the reistry. LogWrite ("Bitness is: ($Office2016)") #Added some error logic here as this line seems to throw fast errors and closes the PS window. I added logic to write the error it outputs right in the log file. if ($Office2016 = $error){ Write-Output $Office2016 | Out-File 'C:\WinPatches.log' -Append utf8 } # Checking for Bitness version and installing patches based on x86 or x64 architecture #--------------------------------------------------------------------------------------------------------------------- LogWrite ("verifying office 2016 version") if ($Office2016 -eq "x86"){ Start-Process "msiexec.exe" -wait -ArgumentList '/p .\KB3085368x86\KB3085368x86.msp /QN' if ($ProcessError){ LogWrite("There was an error in the installation") } Logwrite("Installation Successful") Start-Sleep 10 Start-Process "msiexec.exe" -wait -ArgumentList '/p .\KB4484198x86\KB4484198x86.msp /QN' if ($ProcessError){ LogWrite("There was an error in the installation") } Logwrite("Installation Successful") } elseif ($Office2016 -eq "x64"){ Start-Process "msiexec.exe" -wait -ArgumentList '/p .\KB3085368x64\KB3085368x64.msp /QN' if ($ProcessError){ LogWrite("There was an error in the installation") } Logwrite("Installation Successful") Start-Sleep 10 Start-Process "msiexec.exe" -wait -ArgumentList '/p .\KB4484198x64\KB4484198x64.msp /QN' if ($ProcessError){ LogWrite("There was an error in the installation") } Logwrite("Installation Successful") } # Confirmation of script execution and date/time Logwrite("Installation Ended: $TStamp") Exit-PSSession
Any help is appreciated.