# Script to install Microsoft Office versions 2016-2024. # Technolog Networks - 2024-09-16 # iRaven Start-Transcript -Path "c:\irnh\Install-MSOffice.log" -Append $SoftwareDeployLocation = "\\minuette2.technolog.net\SoftwareLibrary\Software\MSOffice" $ParamVersion = $args[0] # Office Install Checks echo "Checking currently installed Office version (if applicable)..." $OfficeVersionInstalled = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Office*" | select Name, Version).Version $Office2016 = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Office*2016" | select Name, Version) $Office2019 = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Office*2019" | select Name, Version) $Office2021 = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Office*2021" | select Name, Version) $Office2024 = (Get-WmiObject -Class Win32_Product | where name -like "Microsoft Office*2024" | select Name, Version) Function CheckInstall { if ($null -ne $OfficeVersionInstalled) { if ($OfficeVersionInstalled -ge "16.0" ) { # Checks if currently installed Office is less than version 16 (2016) if ($null -eq $Office2016 -and $ParamVersion -eq 2016) { Write-Host "Office $ParamVersion is already installed. No action will be taken." return $true } elseif ($null -ne $Office2019 -and $ParamVersion -eq 2019) { Write-Host "Office $ParamVersion is already installed. No action will be taken." return $true } elseif ($null -ne $Office2021 -and $ParamVersion -eq 2021) { Write-Host "Office $ParamVersion is already installed. No action will be taken." return $true } elseif ($null -ne $Office2024 -and $ParamVersion -eq 2024) { Write-Host "Office $ParamVersion is already installed. No action will be taken." return $true } else { Write-Host "The office version currently installed is different from specified ($ParamVersion). Upgrading to $ParamVersion." return $false } } else { Write-Host "An older version of Office is already installed. Upgrading to $ParamVersion." return $true } } else { Write-Host "Office is not installed at all." return $false } } if ((CheckInstall) -eq $false) { cd $SoftwareDeployLocation if ($ParamVersion -eq 2016){ try { .\OfficeProPlus2016_VL\setup.exe /adminfile TNGOffice16Deploy.msp } catch { Write-Host "Office $ParamVersion could not be installed." } } elseif ($ParamVersion -eq 2021) { try { .\setup.exe /configure office2021_deploy.xml } catch { Write-Host "Office $ParamVersion could not be installed." } } elseif ($ParamVersion -eq 2024) { try { .\setup.exe /configure office2024_deploy.xml } catch { Write-Host "Office $ParamVersion could not be installed." } } } Stop-Transcript