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?
