Script Download: FixIssuesDescribedinKB947215(PowerShell).zip
http://gallery.technet.microsoft.com/scriptcenter/Script-to-fix-issues-ab65f43e

This sample can help you resolve the issue, “You receive a 'The User Profile Service failed the logon' error message”. This script shows how to list user SID information and delete invalid SID registry keys by using PowerShell Script.

When you log on to a Windows 7-based or a Windows Vista-based computer by using a temporary profile, you receive the following error message:
The User Profile Service failed the logon. User profile cannot be loaded.
To resolve this issue, use the script described in this sample to remove the invalid SID registry key.
image image
image

You can find more All-In-One Script Framework script samples at http://aka.ms/onescriptingallery