Create a Custom Detection Script for Microsoft .NET SDK 7.0 (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 .NET SDK 7.0 using PowerShell.

How to Create a Custom Detection Script for .NET SDK 7.0

Microsoft .NET SDK 7.0 x86 (Registry Detection Method)

## Check for Microsoft .NET SDK 7.0 x86 (Registry Detection Method)
$NETSDK7x86 = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Microsoft .NET SDK 7.0*(x86)' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$NETSDK7x86.DisplayVersion
$NETSDK7x86.PSChildName

## Create Text File with Microsoft .NET SDK 7.0 x86 Registry Detection Method
$FilePath = "C:\Windows\Temp\Microsoft_NET_SDK_7_x86_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If(([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Windows\CurrentVersion\Uninstall\$($NETSDK7x86.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($NETSDK7x86.PSChildName)' -Name DisplayVersion -ea SilentlyContinue)) -ge '$($NETSDK7x86.DisplayVersion)') {"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath

Example:

If(([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Windows\CurrentVersion\Uninstall\{335f3fab-874a-49e8-8b92-5bdabda52956}','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{335f3fab-874a-49e8-8b92-5bdabda52956}' -Name DisplayVersion -ea SilentlyContinue)) -ge '7.1.22.30718') {
Write-Host "Installed"
}

Microsoft .NET SDK 7.0 x64 (Registry Detection Method)

## Check for Microsoft .NET SDK 7.0 x64 (Registry Detection Method)
$NETSDK7x64 = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Microsoft .NET SDK 7.0*(x64)' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$NETSDK7x64.DisplayVersion
$NETSDK7x64.PSChildName

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

Example:

If(([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Windows\CurrentVersion\Uninstall\{59b7b560-ddd1-4b84-a9a6-90d0bb8fcc45}','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{59b7b560-ddd1-4b84-a9a6-90d0bb8fcc45}' -Name DisplayVersion -ea SilentlyContinue)) -ge '7.1.22.30718') {
Write-Host "Installed"
}

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.

Recent Posts