Actions

Application Management Tutorial: Reset NotFoundInRepo registry value

From Syntaro Help

This tutorial describes how you can create a package to reset the NotFoundInRepo values for all packages on your clients. The Script in the Install Section, will do the following things:

  • Check if you have packages in the registry that have a NotFoundInRepo value higher then 0
  • If there are values higher than 0 it will reset them to 0 and create a new Temporary Scheduled Task called Syntaro Full Installer after NotFoundInRepo reset
  • That task will then be executed 2 minutes later, to make sure that the client gets all the packages it needs in the correct versions.
  • The task will delete itself after one day.
  • The script will in any case write the key HKLM\SOFTWARE\Syntaro\ApplicationManagement\ResetNotFoundInRepo\ResetNotFoundInRepo, to make sure it gets executed only once.


Create a new package and a version

You can create a new Syntaro Package in the Application Management Module.
PackageName = baseVISION_ResetNotFoundInRepo
Version Name: 1.0

In the command section enter the following code

Detection

$AppManagementRegKey = "HKLM:\SOFTWARE\Syntaro\ApplicationManagement"
$CheckKeyPath = $AppManagementRegKey +"\ResetNotFoundInRepo"
$CheckKeyName = "ResetNotFoundInRepo"
$CheckKeyValue = 1

If((Get-ItemProperty -Name $CheckKeyName -Path $CheckKeyPath -ErrorAction SilentlyContinue) -ne $null){
    Write-Log ("$CheckKeyPath\$CheckKeyName exists checking it's value")
    $currentRegKeyValue = Get-ItemPropertyValue -path $CheckKeyPath -Name $CheckKeyName
    If($currentRegKeyValue -eq $CheckKeyValue){
        Write-Log ("It's value is $currentRegKeyValue and that is equal to $CheckKeyValue")
        Write-Log ("The package is installed")
        $ScriptalreadyExecuted = $true
    }
    else{
        Write-Log ("Its value is $currentRegKeyValue and that is not equal to $CheckKeyValue")
        Write-Log ("The package is not installed")
        $ScriptalreadyExecuted = $false
    }
}
else{
    Write-Log ("$CheckKeyPath\$CheckKeyName dosen't exist.")
    Write-Log ("The package is not installed")
    $ScriptalreadyExecuted = $false
}

$ScriptalreadyExecuted

Requirements

$True

Install

$AppManagementRegKey = "HKLM:\SOFTWARE\Syntaro\ApplicationManagement"
$CheckKeyPath = $AppManagementRegKey +"\ResetNotFoundInRepo"
$CheckKeyName = "ResetNotFoundInRepo"
$CheckKeyValue = 1
$Now = get-date
$NowPlus2 = $Now.AddMinutes(2)
$ScheduledTaskName = "Syntaro Full Installer"
$TempScheduledTaskName = "$ScheduledTaskName after NotFoundInRepo reset"


#Check if there are NotFoundInRepo values that are greater than 0
$ChildItemsWithNotFoundInRepoGT0 = Get-ChildItem $AppManagementRegKey | Get-ItemProperty | Where-Object NotFoundInRepo -gt 0

If($ChildItemsWithNotFoundInRepoGT0.count -gt 0){
    Write-Log ("Found " +$ChildItemsWithNotFoundInRepoGT0.count +" Applications where the NotFoundInRepo Value is greater than 0")
    Write-Log ("I will reset them to 0")
    #Reset the not NotFoundInRepo vlaues to 0
    ForEach($ChildItem in $ChildItemsWithNotFoundInRepoGT0){
        $CurrentApplication = ($ChildItem | Get-ItemProperty).Name
        Write-Log ("Reseting NotFoundInRepo for the application $CurrentApplication")
        $ChildItem | Set-ItemProperty -Name NotFoundInRepo -Value 0
    }
    Write-Log ("I finished resetting the values")

#Create a new ScheduledTask that only runs once and gets deleted after one day
    try{

        $CurrentTask = Get-ScheduledTask -TaskName $ScheduledTaskName

        $NewTaskTrigger =  New-ScheduledTaskTrigger -Once -at $NowPlus2

        Register-ScheduledTask -TaskName $TempScheduledTaskName -Action ($CurrentTask.Actions) -Trigger $NewTaskTrigger -User "NT AUTHORITY\SYSTEM" -RunLevel Highest | out-null

        #Now i need to update the task with the parameters so it deletes it self after one day
        $TaskToUpdate = Get-ScheduledTask -TaskName $TempScheduledTaskName
        $TaskToUpdate.Settings.DeleteExpiredTaskAfter = 'PT0S'
        $TaskToUpdate.Settings.MultipleInstances= "Queue"
        $TaskToUpdate.Settings.DisallowStartIfOnBatteries = $False
        $TaskToUpdate.Settings.StopIfGoingOnBatteries = $False
        $TaskToUpdate.Settings.StartWhenAvailable = $True
        $TaskToUpdate.Settings.RunOnlyIfNetworkAvailable = $True
        $TaskToUpdate.Triggers[0].EndBoundary = [DateTime]::Now.AddDays(1).ToString("yyyy-MM-dd'T'HH:mm:ss")
        $TaskToUpdate | Set-ScheduledTask | out-null
        Write-Log ("I created a new ScheduledTask called '$TempScheduledTaskName' that will get executed at $NowPlus2")
        Write-Log ("This ScheduledTask will delete it self in one day")

    }
    catch{
        Write-Log ("I failed creating the new ScheduledTask called '$TempScheduledTaskName'") -Type Error -Exception $_.Exception
    }
}
else{
    Write-Log ("Found no applications where the NotFoundInRepo Value is greater than 0")
    Write-Log ("So there is no need to reset them")
}


#Setting the Regkey, so that the detect script nows that everything is ok.

#Check if Registry Path exists and create it if not
If((Test-Path "$CheckKeyPath") -eq $false){
    Write-Log ("$CheckKeyPath doesn't already exist I need to create it.")
    New-Item -Path $CheckKeyPath | Out-Null
}

#Set $CheckKeyName to the desiered $CheckKeyValue Value or create it if it dosen't exist
If((Get-ItemProperty -Name $CheckKeyName -Path $CheckKeyPath -ErrorAction SilentlyContinue) -ne $null){
    Write-Log ("I set $CheckKeyPath\$CheckKeyName to $CheckKeyValue")
    Set-ItemProperty -Path $CheckKeyPath -Name "$CheckKeyName" -value $CheckKeyValue | Out-Null
}
else{
    Write-Log ("$CheckKeyPath\$CheckKeyName dosen't already exist. I create it an set it to $CheckKeyValue")
    New-ItemProperty -Path $CheckKeyPath -Name "$CheckKeyName" -value $CheckKeyValue | Out-Null
}

Uninstall

$AppManagementRegKey = "HKLM:\SOFTWARE\Syntaro\ApplicationManagement"
$CheckKeyPath = $AppManagementRegKey +"\ResetNotFoundInRepo"

#Check if Registry Path exists and create it if not
If((Test-Path "$CheckKeyPath") -eq $True){
    Write-Log ("$CheckKeyPath exists I will remove it")
    Remove-Item -Path $CheckKeyPath | Out-Null
}
else{
    Write-Log ("$CheckKeyPath doesn't exist I don't need to remove it")
}

Deploy the Package with Intune

Now its time to deploy that new Package with intune how this can be done is described here.
But make sure you deploy the new package not to all clients at once!
But test it first with only one client or a few clients.

I want to rerun the package again

If you need the script to be rerun again you can simply do the following things:

  • Inside your Syntaro Portal copy the existing Version of your current Version
  • Give it a new Version Name
  • Increase the value of the variable $CheckKeyValue in the Detection and the Install section. But make sure you use the same Value in both sections.
  • Change the ring of that version to where you want the new version to be deployed.