Create a Custom Detection Script for Mendeley Reference Manager (PowerShell)

Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM) and Microsoft Intune use Detection Rules to determine the presence of Applications & Win32 Apps. The detection rules ensure that application installations only begin to run if the application is not already installed on the device. This article will serve as an informative guide and give you a clear understanding of how to create an updated custom detection script for each new version of Mendeley Reference Manager using PowerShell.

How to Create a Custom Detection Script for Mendeley Reference Manager

Mendeley Reference Manager (File Detection Method)

## Check for Mendeley Reference Manager (File Detection Method)
$MendeleyExe = (Get-ChildItem -Path "C:\Program Files\Mendeley Reference Manager\Mendeley Reference Manager.exe","C:\Program Files (x86)\Mendeley Reference Manager\Mendeley Reference Manager.exe" -ErrorAction SilentlyContinue)
$MendeleyExe.FullName
$MendeleyPath = $($MendeleyExe.FullName).Replace("C:\Program Files\","").Replace("C:\Program Files (x86)\","")
$FileVersion = (Get-Item -Path "$($MendeleyExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion

## Create Text File with Mendeley Reference Manager File Detection Method
$FilePath = "C:\Windows\Temp\Mendeley_Reference_Manager_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([String](Get-Item -Path `"`$Env:ProgramFiles\$MendeleyPath`",`"`${Env:ProgramFiles(x86)}\$MendeleyPath`" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge `"$FileVersion`"){"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "Exit 0"
Add-Content -Path "$FilePath" -Value "}"
Add-Content -Path "$FilePath" -Value "else {"
Add-Content -Path "$FilePath" -Value "Exit 1"
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath
  • Click Run Script (F5)
  • A text file will open with the Mendeley Reference Manager Detection Method script required to detect the current version of Mendeley Reference Manager that is installed on the device you are running the script from.

Example:

If([String](Get-Item -Path "$Env:ProgramFiles\Mendeley Reference Manager\Mendeley Reference Manager.exe","${Env:ProgramFiles(x86)}\Mendeley Reference Manager\Mendeley Reference Manager.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "2.75.0.180"){
Write-Host "Installed"
Exit 0
}
else {
Exit 1
}

Mendeley Reference Manager (Registry Detection Method)

## Check for Mendeley Reference Manager (Registry Detection Method)
$Mendeley = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -match 'Mendeley Reference Manager' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$Mendeley.DisplayVersion
$Mendeley.PSChildName

## Create Text File with Mendeley Reference Manager Registry Detection Method
$FilePath = "C:\Windows\Temp\Mendeley_Reference_Manager_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($Mendeley.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($Mendeley.PSChildName)' -Name DisplayVersion -ea SilentlyContinue) -ge '$($Mendeley.DisplayVersion)') {"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "Exit 0"
Add-Content -Path "$FilePath" -Value "}"
Add-Content -Path "$FilePath" -Value "else {"
Add-Content -Path "$FilePath" -Value "Exit 1"
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath
  • Click Run Script (F5)
  • A text file will open with the Mendeley Reference Manager Detection Method script required to detect the current version of Mendeley Reference Manager that is installed on the device you are running the script from.

Example:

If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\b4b58389-01e4-5dfd-9842-aad36733657a','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\b4b58389-01e4-5dfd-9842-aad36733657a' -Name DisplayVersion -ea SilentlyContinue) -ge '2.75.0') {
Write-Host "Installed"
Exit 0
}
else {
Exit 1
}

Always make sure to test everything in a development environment prior to implementing anything into production. The information in this article is provided “As Is” without warranty of any kind.