0
votes

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?

1
Possible duplicate of How to detect installed version of MS-Office?user6811411

1 Answers

1
votes

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!"

}