Remove-ADTFileFromUserProfiles - Is PSADT v.4.1.0 not gracefully handling corrupt user profiles?

I ran into a strange issue today with the Remove-ADTFileFromUserProfiles function. I used Co-Pilot to help me triage the issue, but this function was failing on a specific computer that probably has some corrupt profiles on it.

While those profiles should be cleaned up I was wondering if this should be reported as a Bug or a requested feature.

I would assume if PSADT encounters a profile that is corrupt, it should handle the issue a little more gracefully.

Below is the CoPilot conversation with the errors and it’s recommendations. I opted for the Try/Catch statement for now. But even with that in place, it seems that once it errored it didn’t attempt to traverse any other profiles, and I am unsure which profile it tripped up on, because the function didn’t log that.

Original Code Block:

$lnk = @('Cashier.lnk',
    'Cashier-Test.lnk'
)

foreach ($item in $lnk) {  
    Remove-ADTFileFromUserProfiles -Path "Desktop\$($item)"           
    Remove-ADTFile -Path "$($envCommonDesktop)\$($item)"
}

–CoPilot Conversation–

References: PSAppDeployToolkit.psm1 Invoke-AppDeployToolkit.ps1
[Pre-Install] :: The property 'ProfileImagePath' cannot be found on this object. Verify that the property exists.Error Record:

 Message : The property 'ProfileImagePath' cannot be found on this object. Verify that the property exists. FullyQualifiedErrorId : PropertyNotFoundStrict,Get-ADTUserProfilesScriptStackTrace : at <ScriptBlock><Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 8669                        at Get-ADTUserProfiles<Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 8636                        at Remove-ADTFileFromUserProfiles<Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 13214                        at Install-ADTDeployment, C:\WINDOWS\ccmcache\38\Invoke-AppDeployToolkit.ps1: line 187                        at <ScriptBlock>, C:\WINDOWS\ccmcache\38\Invoke-AppDeployToolkit.ps1: line 735                        at <ScriptBlock>, <No file>: line 1 PositionMessage : At C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1:13214 char:39                        + ... ilePath in (& $Script:CommandTable.'Get-ADTUserProfiles' @GetUserProf ...                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Pre-Install] :: An unhandled error within [Invoke-AppDeployToolkit.ps1] has occurred.Error Record:

 Message : The property 'ProfileImagePath' cannot be found on this object. Verify that the property exists. FullyQualifiedErrorId : PropertyNotFoundStrict,Get-ADTUserProfilesScriptStackTrace : at <ScriptBlock><Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 8669                        at Get-ADTUserProfiles<Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 8636                        at Remove-ADTFileFromUserProfiles<Process>, C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1: line 13214                        at Install-ADTDeployment, C:\WINDOWS\ccmcache\38\Invoke-AppDeployToolkit.ps1: line 187                        at <ScriptBlock>, C:\WINDOWS\ccmcache\38\Invoke-AppDeployToolkit.ps1: line 735                        at <ScriptBlock>, <No file>: line 1 PositionMessage : At C:\WINDOWS\ccmcache\38\PSAppDeployToolkit\PSAppDeployToolkit.psm1:13214 char:39                        + ... ilePath in (& $Script:CommandTable.'Get-ADTUserProfiles' @GetUserProf ...                        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[Finalization] :: [iNovah2Cashier] install completed in [1.2495065] seconds with exit code [60001].

The error:

The property 'ProfileImagePath' cannot be found on this object. Verify that the property exists.

FullyQualifiedErrorId : PropertyNotFoundStrict,Get-ADTUserProfiles

means that Get-ADTUserProfiles is returning an object that does not have the property ProfileImagePath. This is usually caused by:

  • A corrupt or incomplete user profile in the registry.

  • A system profile or service account without a ProfileImagePath.

  • A bug in the toolkit or a change in Windows profile handling.

How to fix:

You should filter out any user profiles that do not have a ProfileImagePath property before using them.
You can do this by updating your call to Remove-ADTFileFromUserProfiles or by patching the toolkit function.

Workaround in your script:

Wrap the call in a try/catch, or filter profiles:

foreach ($item in $lnk) {
    try {
        Remove-ADTFileFromUserProfiles -Path "Desktop\$($item)"
    } catch {
        Write-ADTLogEntry -Message "Failed to remove $item from user profiles: $($_.Exception.Message)" -Severity 2
    }
    Remove-ADTFile -Path "$($envCommonDesktop)\$($item)"
}

Or, if you can edit the toolkit:
Patch Get-ADTUserProfiles to skip objects without ProfileImagePath:

# In Get-ADTUserProfiles, after collecting profiles:
$profiles = $profiles | Where-Object { $_.PSObject.Properties['ProfileImagePath'] }

Summary:
This is a common issue with user profile enumeration on Windows. Filtering out profiles without ProfileImagePath will resolve the error and allow your deployment to continue.

–END CoPilot Conversation—


While the above Try/Catch statement helped my script to successfully run on the offending computer. I wanted to see what the Community says about this issue and if there is a better way to handle this? Or should i report this as a bug in GitHub?

It does now :sign_of_the_horns:

2 Likes

@bohnanza22 that is a great example of how to explain a (potential) problem - thanks for the effort, I guess the great explaination leads to yet another great solution :grin: - Thanks @mjr4077au

2 Likes

@Adrian_Scott ADHD to the rescue at last! :wink: . At first I felt like I needed to add more detail from the logs or attach the logs. But I realized too late and didn’t really have a way of retrieving them again.

@mjr4077au I appreciate the quick response. Thanks again!

I assume the fix was made in the Remove-ADTFileFromUserProfiles function so I can download a fresh copy of 4.1 and drop my current Invoke-AppDeployToolkit.ps1 into it, to pick up the changes?

1 Like

The fix was made within Get-ADTUserProfiles, but yeah just download 4.1.0 and you’ll be off to the races :sign_of_the_horns:

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.