Added logic to skip when Office is already installed
This commit is contained in:
@@ -17,17 +17,14 @@ at http://practical365.com
|
|||||||
Specify the UNC path to the network share that hosts the Office 365
|
Specify the UNC path to the network share that hosts the Office 365
|
||||||
setup and configuration files.
|
setup and configuration files.
|
||||||
|
|
||||||
.PARAMETER OfficeVersion
|
|
||||||
Specify the Office CTR version to deploy (e.g. 2013, or 2016)
|
|
||||||
|
|
||||||
.PARAMETER SKU
|
.PARAMETER SKU
|
||||||
Specify the the Office CTR SKU to deploy (e.g. ProPlus, Business)
|
Specify the the Office CTR SKU to deploy (e.g. ProPlus, Business)
|
||||||
|
|
||||||
.PARAMETER
|
.PARAMETER Channel
|
||||||
|
Specify the build channel to deploy (e.g. Current, Deferred)
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\Verb-NounsAndThings.ps1
|
.\Install-OfficeCTR.ps1 -InstallRoot \\mgmt\Installs\OfficeCTR -SKU ProPlus -Channel Deferred
|
||||||
What does this example do...
|
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
Written by: Paul Cunningham
|
Written by: Paul Cunningham
|
||||||
@@ -69,32 +66,63 @@ param (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
$ConfigurationXML = "$($InstallRoot)\$($SKU)\$($Channel)\configuration.xml"
|
function DoInstall {
|
||||||
|
|
||||||
If (!(Test-Path $ConfigurationXML)) {
|
$ConfigurationXML = "$($InstallRoot)\$($SKU)\$($Channel)\configuration.xml"
|
||||||
throw "Unable to locate a configuration XML file at $($ConfigurationXML)"
|
|
||||||
}
|
|
||||||
|
|
||||||
$setuppath = "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe"
|
If (!(Test-Path $ConfigurationXML)) {
|
||||||
|
throw "Unable to locate a configuration XML file at $($ConfigurationXML)"
|
||||||
if (!(Test-Path $setuppath)) {
|
|
||||||
throw "Unable to locate a Setup.exe file at $($setuppath)"
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Attempting to install Office 365 $($SKU) $($Channel)"
|
|
||||||
|
|
||||||
try {
|
|
||||||
$process = Start-Process -FilePath "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe" -ArgumentList "/Configure $($InstallRoot)\$($SKU)\$($Channel)\configuration.xml" -Wait -PassThru -ErrorAction STOP
|
|
||||||
|
|
||||||
if ($process.ExitCode -eq 0)
|
|
||||||
{
|
|
||||||
Write-Host -ForegroundColor Green "Office setup started without error."
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
$setuppath = "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe"
|
||||||
Write-Warning "Installer exit code $($process.ExitCode)."
|
|
||||||
|
if (!(Test-Path $setuppath)) {
|
||||||
|
throw "Unable to locate a Setup.exe file at $($setuppath)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Attempting to install Office 365 $($SKU) $($Channel)"
|
||||||
|
|
||||||
|
try {
|
||||||
|
$process = Start-Process -FilePath "$($InstallRoot)\$($SKU)\$($Channel)\Setup.exe" -ArgumentList "/Configure $($InstallRoot)\$($SKU)\$($Channel)\configuration.xml" -Wait -PassThru -ErrorAction STOP
|
||||||
|
|
||||||
|
if ($process.ExitCode -eq 0)
|
||||||
|
{
|
||||||
|
Write-Host -ForegroundColor Green "Office setup started without error."
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Warning "Installer exit code $($process.ExitCode)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Warning $_.Exception.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#Check if Office is already installed, as indicated by presence of registry key
|
||||||
|
$RegistryPath = 'HKLM:\SOFTWARE\Microsoft\Office\16.0\ClickToRunStore\Packages\{9AC08E99-230B-47e8-9721-4577B7F124EA}'
|
||||||
|
|
||||||
|
if (Test-Path $RegistryPath) {
|
||||||
|
#Check for children
|
||||||
|
|
||||||
|
$Item = Get-ItemProperty -Path $RegistryPath
|
||||||
|
|
||||||
|
if (!($Item.'(default)' -eq $null)) {
|
||||||
|
#Office is installed, according to registry key. Nothing further to do.
|
||||||
|
EXIT
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#Registry key exists but default value is empty, install needed
|
||||||
|
DoInstall
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
else {
|
||||||
Write-Warning $_.Exception.Message
|
#Registry key doesn't exist, install needed
|
||||||
|
DoInstall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user