Script versioni di Microsoft Office installate nei client di una rete Windows

()

Utile in contesti aziendali gestiti con AD o intune.


Funzionalità:
– Esegue una query WMI sui client remoti.

  • Cerca le versioni di Office installate (MSI e Click-to-Run).
  • Restituisce nome, versione, tipo di installazione e architettura.
  • Compatibile con Windows 10/11, Office 2013-2021, Microsoft 365 Apps.

Prerequisiti:
– PowerShell Remoting abilitato sui client (WinRM).

  • Eseguito da un utente con permessi di amministrazione remota.
  • Possibilità di esportare i risultati in CSV per inventario.

Codice:

Lista dei client su cui eseguire l’audit (può provenire anche da AD)

$computerList = Get-Content -Path “.\client_list.txt”

Risultati finali

$officeInventory = @()

foreach ($computer in $computerList) {
Write-Host “Controllo su: $computer” -ForegroundColor Cyan
try {
$officeProducts = Invoke-Command -ComputerName $computer -ScriptBlock {
$products = @()
# Check Click-to-Run
$c2r = Get-ItemProperty -Path “HKLM:\Software\Microsoft\Office\ClickToRun\Configuration” -ErrorAction SilentlyContinue
if ($c2r) {
$products += [PSCustomObject]@{
Computer = $env:COMPUTERNAME
Product = $c2r.ProductReleaseIds
Version = $c2r.VersionToReport
Architecture = $c2r.Platform
InstallType = “Click-to-Run”
}
}

        # Check MSI
        $msiProducts = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -ErrorAction SilentlyContinue |
            Where-Object { $.DisplayName -like "Office" -or $.DisplayName -like "Microsoft 365" }

        foreach ($p in $msiProducts) {
            $products += [PSCustomObject]@{
                Computer     = $env:COMPUTERNAME
                Product      = $p.DisplayName
                Version      = $p.DisplayVersion
                Architecture = if ($p.DisplayName -match "64") {"x64"} else {"x86"}
                InstallType  = "MSI"
            }
        }

        return $products
    }

    $officeInventory += $officeProducts
} catch {
    Write-Warning "Errore nel contattare $computer: $_"
}

}

Esportazione risultati

$officeInventory | Export-Csv -Path “.\Office_Inventory.csv” -NoTypeInformation -Encoding UTF8

Write-Host “Audit completato. Risultati salvati in Office_Inventory.csv” -ForegroundColor Green
Note aggiuntive:
Il file client_list.txt deve contenere un client per riga (FQDN o nome NetBIOS).

Può essere eseguito da un server centrale o PC admin con accesso remoto.

Per ambienti AD puoi ottenere i nomi dei PC con:

Get-ADComputer -Filter * -Property Name | Select-Object -ExpandProperty Name > client_list.txt


  1. Versione per Intune – Proactive Remediation
    Questa versione può essere distribuita tramite Endpoint Manager (Intune) con la funzionalità Proactive Remediations per controllare la versione di Office localmente su ogni device gestito.

Script di Detection

Detection Script – Rileva versioni Office

$results = @()

Click-to-Run

$c2r = Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration” -ErrorAction SilentlyContinue
if ($c2r) {
$results += “$($c2r.ProductReleaseIds) – $($c2r.VersionToReport) – C2R”
}

MSI

$msi = Get-ItemProperty -Path “HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall*” -ErrorAction SilentlyContinue |
Where-Object { $.DisplayName -like “Office” -or $.DisplayName -like “Microsoft 365” }

foreach ($entry in $msi) {
$results += “$($entry.DisplayName) – $($entry.DisplayVersion) – MSI”
}

if ($results.Count -gt 0) {
Write-Output ($results -join “`n”)
exit 1 # Detection positiva
}

exit 0 # Nessuna installazione trovata
Script di Remediation (facoltativo)
Puoi personalizzare questo script per disinstallare versioni non autorizzate o inviare un log a un endpoint aziendale. Posso aiutarti a crearlo in base alle tue policy.

  1. Script con Report HTML (per ambienti AD o PowerShell Remoting)
    Questo script è una variante del precedente che genera un report HTML con colorazione per tipo di installazione.

Codice Sintetico

Dopo aver raccolto i dati come nello script precedente

$reportPath = “.\Office_Inventory_Report.html”

$officeInventory | ConvertTo-Html -Property Computer, Product, Version, Architecture, InstallType -Head "<style>table {border-collapse:collapse;} td,th {border:1px solid black; padding:5px;} .C2R {background-color:#e0f7fa;} .MSI {background-color:#ffe0b2;}</style>"
-PostContent “

Generato il: $(Get-Date)” |
ForEach-Object {
$_ -replace “(.?)(.?)(.?)(.?)(Click-to-Run|MSI)”,
‘$1$2$3$4$5’
} | Out-File -Encoding utf8 $reportPath

Start-Process $reportPath


/ 5
Grazie per aver votato!

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?