commandline.info

Detection/Requirement Recipes

Praxisbeispiele fuer Intune und MECM: Registry, Datei, ProductCode und Versionen.

Recipe: MSI ProductCode

# PowerShell Detection Script (Intune)
$guid = '{11111111-2222-3333-4444-555555555555}'
$paths = @(
  "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$guid",
  "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$guid"
)
if ($paths | Where-Object { Test-Path $_ }) { exit 0 } else { exit 1 }

Recipe: Registry Versioncheck

$key = 'HKLM:\SOFTWARE\Contoso\App'
$min = [version]'5.4.1'
if (Test-Path $key) {
  $cur = [version](Get-ItemPropertyValue -Path $key -Name Version)
  if ($cur -ge $min) { exit 0 }
}
exit 1

Recipe: File Detection

$file = 'C:\Program Files\Contoso\app.exe'
if (Test-Path $file) {
  $v = [version](Get-Item $file).VersionInfo.FileVersion
  if ($v -ge [version]'2.3.0.0') { exit 0 }
}
exit 1

Requirement Examples

# 64-bit OS Requirement
if ([Environment]::Is64BitOperatingSystem) { exit 0 } else { exit 1 }

# Min free disk (2 GB)
$freeGb = (Get-PSDrive -Name C).Free / 1GB
if ($freeGb -ge 2) { exit 0 } else { exit 1 }