Ever wanted to know how to use the script detection method of an application in ConfigMgr with PowerShell, its quite simple really once you have been shown what ConfigMgr expects to be returned.
The detection method bellow is a PowerShell Test-Path statement. If the statement returns “True”, meaning the file is there, then the script shouts out to the ConfigMgr client to say the detection method is satisfied. You MUST keep the Else clause in the script empty or it will fail to evaluate although there is nothing to be run in it.
if( Test-Path "$env:LOCALAPPDATA\Microsoft\Onedrive\OneDrive.exe" ) { Write-Host "installed" } else { }
Now as i’m sure you’ve guessed with the example this becomes really usefull when deploying applications that install in the users %LocalAPPDATA% as ConfigMgr currently cannot query that location as all installs run as system.
Here is another testing two paths.
if( ( Test-Path "$env:LOCALAPPDATA\Microsoft\Onedrive\OneDrive.exe" ) -and ( test-path "HKCU:\SOFTWARE\Microsoft\OneDrive\17.3.6390.0509" ) ) { Write-Host "installed" } else { }
These examples should let you build all sorts of detection methods now. It doesn’t have to be test path either, it could be anything like checking if a registry entry value is “greater than or equal to”.