Create a Custom Detection Script for the Microsoft Azure Universal Print Connector (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 the Microsoft Azure Universal Print Connector using PowerShell.

How to Create a Custom Detection Script for the Microsoft Azure Universal Print Connector

Microsoft Azure Universal Print Connector (File Detection Method)

## Check for Microsoft Azure Universal Print Connector (File Detection Method)
$PrintConnectorAppExe = (Get-ChildItem -Path "C:\Program Files\PrintConnector\PrintConnectorApp.exe" -ErrorAction SilentlyContinue)
$PrintConnectorAppExe.FullName
$PrintConnectorAppPath = $($PrintConnectorAppExe.FullName).Replace("C:\Program Files\","")
$FileVersion = (Get-Item -Path "$($PrintConnectorAppExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion

## Create Text File with Microsoft Azure Universal Print Connector File Detection Method
$FilePath = "C:\Windows\Temp\Universal_Print_Connector_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([String](Get-Item -Path `"`$Env:ProgramFiles\$PrintConnectorAppPath`" -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 Microsoft Azure Universal Print Connector Detection Method script required to detect the current version of Microsoft Azure Universal Print Connector that is installed on the device you are running the script from.

Example:

If([String](Get-Item -Path "$Env:ProgramFiles\PrintConnector\PrintConnectorApp.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "1.84.8342.42248"){
Write-Host "Installed"
Exit 0
}
else {
Exit 1
}

Microsoft Azure Universal Print Connector (Registry Detection Method)

## Check for Microsoft Azure Universal Print Connector (Registry Detection Method)
$PrintConnectorApp = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -match 'Universal Print Connector' -and $_.UninstallString -notlike '*MsiExec.exe*' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$PrintConnectorApp.DisplayVersion
$PrintConnectorApp.PSChildName

## Create Text File with Microsoft Azure Universal Print Connector Registry Detection Method
$FilePath = "C:\Windows\Temp\Universal_Print_Connector_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($PrintConnectorApp.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($PrintConnectorApp.PSChildName)' -Name DisplayVersion -ea SilentlyContinue) -ge '$($PrintConnectorApp.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 Microsoft Azure Universal Print Connector Detection Method script required to detect the current version of the Microsoft Azure Universal Print Connector that is installed on the device you are running the script from.

Example:

If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{4004c2c7-7f9f-4467-9a76-174f3e91ebc2}','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{4004c2c7-7f9f-4467-9a76-174f3e91ebc2}' -Name DisplayVersion -ea SilentlyContinue) -ge '1.84.8342.42256') {
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.