116 lines
4.6 KiB
PowerShell
116 lines
4.6 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Script di livello enterprise per automatizzare il download e l'installazione di Microsoft Office tramite l'ODT.
|
|
.DESCRIPTION
|
|
Questo script autonomo gestisce l'intero processo: download dell'ultima versione dell'ODT, estrazione silenziosa,
|
|
e installazione di Microsoft 365 Apps for Enterprise basata su una configurazione predefinita.
|
|
.PARAMETER WorkingDirectory
|
|
Directory temporanea per il download e l'estrazione dei file.
|
|
.PARAMETER Mode
|
|
Specifica la modalità di esecuzione: 'Download', 'Configure' o 'All'.
|
|
.EXAMPLE
|
|
.\Deploy-Office.ps1 -Mode All
|
|
#>
|
|
|
|
param(
|
|
[Parameter(Mandatory = $false)]
|
|
[string]$WorkingDirectory = "C:\Temp\ODT_Install",
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
|
|
[string]$Mode = 'All'
|
|
)
|
|
|
|
# --- Inizio Esecuzione ---
|
|
|
|
# Definizione della configurazione XML di Office
|
|
# Questo script installa Microsoft 365 Apps for Enterprise (64-bit) dal canale "Current".
|
|
# Esclude Groove, Lync e Teams. L'installazione è silenziosa.
|
|
$OfficeConfigurationXml = @"
|
|
<Configuration>
|
|
<Add OfficeClientEdition="64" Channel="Current">
|
|
<Product ID="O365ProPlusRetail">
|
|
<Language ID="MatchOS" />
|
|
<ExcludeApp ID="Groove" />
|
|
<ExcludeApp ID="Lync" />
|
|
<ExcludeApp ID="Teams" />
|
|
</Product>
|
|
</Add>
|
|
<RemoveMSI />
|
|
<Display Level="None" AcceptEULA="TRUE" />
|
|
<Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
|
|
</Configuration>
|
|
"@
|
|
|
|
# Funzione per ottenere l'URL di download più recente dell'ODT
|
|
function Get-LatestOdtUrl {
|
|
try {
|
|
$response = Invoke-WebRequest -Uri "https://www.microsoft.com/en-us/download/details.aspx?id=49117" -UseBasicParsing
|
|
$url = $response.Links | Where-Object { $_.href -like "*officedeploymenttool*.exe" } | Select-Object -ExpandProperty href -First 1
|
|
return $url
|
|
}
|
|
catch {
|
|
Write-Error "Impossibile recuperare l'URL di download dell'ODT. $_"
|
|
return $null
|
|
}
|
|
}
|
|
|
|
try {
|
|
# 1. Preparazione dell'ambiente
|
|
if (-not (Test-Path $WorkingDirectory)) {
|
|
New-Item -Path $WorkingDirectory -ItemType Directory -Force | Out-Null
|
|
Write-Host "Directory di lavoro creata in: $WorkingDirectory"
|
|
}
|
|
$OdtDownloaderPath = Join-Path $WorkingDirectory "officedeploymenttool.exe"
|
|
$SetupExePath = Join-Path $WorkingDirectory "setup.exe"
|
|
$ConfigurationXmlPath = Join-Path $WorkingDirectory "configuration.xml"
|
|
|
|
# Salvataggio del file di configurazione XML
|
|
$OfficeConfigurationXml | Out-File -FilePath $ConfigurationXmlPath -Encoding UTF8
|
|
Write-Host "File di configurazione di Office salvato in: $ConfigurationXmlPath"
|
|
|
|
# 2. Download ed Estrazione dell'ODT (se non già presente)
|
|
if (-not (Test-Path $SetupExePath)) {
|
|
Write-Host "setup.exe non trovato. Avvio del download dell'ODT..."
|
|
$latestOdtUrl = Get-LatestOdtUrl
|
|
if ($latestOdtUrl) {
|
|
Invoke-WebRequest -Uri $latestOdtUrl -OutFile $OdtDownloaderPath
|
|
if (-not (Test-Path $OdtDownloaderPath)) { throw "Download dell'ODT fallito." }
|
|
|
|
Write-Host "Estrazione silenziosa dell'ODT..."
|
|
$extractArgs = "/extract:$WorkingDirectory /quiet"
|
|
Start-Process -FilePath $OdtDownloaderPath -ArgumentList $extractArgs -Wait -NoNewWindow
|
|
if (-not (Test-Path $SetupExePath)) { throw "Estrazione dell'ODT fallita." }
|
|
Write-Host "Estrazione completata con successo."
|
|
}
|
|
} else {
|
|
Write-Host "setup.exe già presente. Saltato il download e l'estrazione."
|
|
}
|
|
|
|
# 3. Esecuzione delle modalità richieste
|
|
if ($Mode -in ('Download', 'All')) {
|
|
Write-Host "Avvio della modalità Download..."
|
|
$downloadArgs = "/download `"$ConfigurationXmlPath`""
|
|
$process = Start-Process -FilePath $SetupExePath -ArgumentList $downloadArgs -Wait -PassThru
|
|
if ($process.ExitCode -ne 0) { throw "La fase di Download è fallita con codice di uscita: $($process.ExitCode)" }
|
|
Write-Host "Download completato con successo."
|
|
}
|
|
|
|
if ($Mode -in ('Configure', 'All')) {
|
|
Write-Host "Avvio della modalità Configure..."
|
|
$configureArgs = "/configure `"$ConfigurationXmlPath`""
|
|
$process = Start-Process -FilePath $SetupExePath -ArgumentList $configureArgs -Wait -PassThru
|
|
if ($process.ExitCode -ne 0) { throw "La fase di Configure è fallita con codice di uscita: $($process.ExitCode)" }
|
|
Write-Host "Configurazione completata con successo."
|
|
}
|
|
|
|
}
|
|
catch {
|
|
Write-Error "Si è verificato un errore durante il processo di distribuzione: $_"
|
|
}
|
|
finally {
|
|
# Opzionale: Pulizia dei file di installazione
|
|
# Remove-Item -Path $WorkingDirectory -Recurse -Force
|
|
# Write-Host "Pulizia della directory di lavoro completata."
|
|
}
|