Intune Custom Detection Script

New Contributor

Hi,

I have the script below to detect if the config.xml file is deployed.  This script runs and deploys the file and I find that in the IntuneManagementExtension log the 'Found XML File' is listed and also believe I have found the app code with 'Detected App'.  It seems the exit code is also zero but the application is not detected.  This Win32App is running in the user context.  

 

I have checked the admin centre and it says the application is installed but this is not what the company portal says, this says its failed.

 

Not sure what I am missing.  Any thoughts as to why the Company Portal does not reflect the correct status?

 

# All files created in the month of November
$CheckMonth = "11"
$CheckYear = "2021"

$UserProfile = $env:USERPROFILE
if (Test-Path "$UserProfile\Appdata\Roaming\System\config.xml") {
$FileMonth = (get-item "$UserProfile\Appdata\Roaming\System\dbconfig.xml").Lastwritetime.month
$FileYear = (get-item "$UserProfile\Appdata\Roaming\System\config.xml").Lastwritetime.Year
$FileDay = (get-item "$UserProfile\Appdata\Roaming\System\config.xml").Lastwritetime.Day
If ($FileMonth -ne $CheckMonth) {Exit}
If ($FileYear -ne $CheckYear) {Exit}
Write-Host "Found XML File" 
}

1 Reply
I always use a write-host and a exit to give back the status. So that would be

$CheckMonth = "11"
$CheckYear = "2021"
$UserProfile = $env:USERPROFILE
if (Test-Path "$UserProfile\Appdata\Roaming\System\config.xml") {
$FileMonth = (get-item "$UserProfile\Appdata\Roaming\System\dbconfig.xml").Lastwritetime.month
$FileYear = (get-item "$UserProfile\Appdata\Roaming\System\config.xml").Lastwritetime.Year
$FileDay = (get-item "$UserProfile\Appdata\Roaming\System\config.xml").Lastwritetime.Day
If ($FileMonth -ne $CheckMonth) { Exit 1 }
If ($FileYear -ne $CheckYear) {
Write-Host "Found XML File"
exit 0
}
}

And you specify FileDay but you don't use it?