Duy Gonzales
Duy Gonzales

Reputation: 53

Powershell Test-Path Office 365 PRO PLUS

I want to use Test-Path for Microsoft Office 365 PRO PLUS.

I used this code but I want to go for the executable to make sure it is really installed. Please see the code below:

$Office = "C:\Program Files\Microsoft Office 15"

$testoffice = Test-Path $Office

If ($testoffice -eq $true) {Write-Host "Office 365 exist!"}

Else {Write-Host "Office 365 doesn't exist!"}

Read-Host "Press enter to exit"

Am I using the right directory for it? Is there an executable to make sure the installation went through and not just the folder?

Upvotes: 1

Views: 3240

Answers (2)

Jose Castillo
Jose Castillo

Reputation: 1

I used rad_'s answer but found that it didn't work for me and had to use something different. I also opened reg edit and did a search for "Microsoft Office 365" just to get the following.

$Office365 = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\16.0\Registration\{003D2533-6A8C4163-9A4E-76376B21ED15}" -Name "ProductName"
$O365 = "Microsoft Office 365"

if ($Office365 -match $O365) {
    Write-Host "You have Office 365, no need for the update. [√]" -ForegroundColor Green
} else {
    Write-Host "No Office 365 installed [X]" -ForegroundColor Red
}

Upvotes: 0

rad_
rad_

Reputation: 301

The best way is via the registry. It checks specifically for 365 and there's no redundancy in case there's a different version of office.

$uninstallKeys = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

$O365 = "Microsoft Office 365"
$O365Check = $uninstallKeys | Where-Object { $_.GetValue("DisplayName") -match $O365 }


if ($O365Check) {

Write-Output "Found Office!"
}
else {

Write-Output "No Office here!"

}

Upvotes: 2

Related Questions