Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Using Test-Path and If statement to check registry path

$
0
0

I'm trying to write a script to check the version (or versions) of Microsoft Office installed on a computer and then take action accordingly. Our environment is primarily Windows 7. PowerShell version is 4. We have a mix of Office 365, 2013, 2010, and 2007.

I'm having trouble understanding the results of my Test-Path registry query. The following portion of script is meant to determine if Office 365 is installed.

The registry path I'm testing for doesn't exist (changed it from a real registry path just for testing purposes), so my first Write-Host statement tells me the variable is False.

The subsequent If statement is saying that the variable is True, because the output from the If statement is "Office version is 365."

Can someone tell me what I'm doing wrong? The variable is False when Test-Path is evaluated, but yet in the context of the If statement, the variable is True. Here's my code:  

$RegPathO365

 

 

 

 

 

="HKLM:\SOFTWARE\blahblahblah"
$O365_installed = (Test-Path$RegPathO365)
Write-Host "O365_installed is $O365_installed."

If ($O365_installed="True") {
     Write-Host"Office version is 365."
}
ElseIf ($O365_installed="False") {
Write-Host"Office version is NOT O365."
}
Else {
Write-Host"Office version is UNKNOWN."
}

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles