Create a Custom Detection Script for Microsoft Azure Service Fabric (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 Microsoft Azure Service Fabric using PowerShell.

How to Create a Custom Detection Script for Microsoft Azure Service Fabric

Microsoft Azure Service Fabric (File Detection Method)

## Check for Microsoft Azure Service Fabric (File Detection Method)
$ServiceFabricExe = (Get-ChildItem -Path "C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code\Fabric.exe" -ErrorAction SilentlyContinue)
$ServiceFabricExe.FullName
$ServiceFabricPath = $($ServiceFabricExe.FullName).Replace("C:\Program Files\","")
$FileVersion = (Get-Item -Path "$($ServiceFabricExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion

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

Example:

If([String](Get-Item -Path "$Env:ProgramFiles\Microsoft Service Fabric\bin\Fabric\Fabric.Code\Fabric.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "9.1.1583.9590"){
Write-Host "Installed"
Exit 0
}
else {
Exit 1
}

Microsoft Azure Service Fabric (Registry Detection Method)

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

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

Example:

If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ServiceFabric' -Name DisplayVersion -ea SilentlyContinue) -ge '9.1.1583.9590') {
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.