I used this PowerShell script:
$searcher = new-object System.DirectoryServices.DirectorySearcher
$searcher.filter=”(&(ObjectClass=computer)(Name=$env:computername))”
$find = $searcher.FindOne()
$thispc = $find.GetDirectoryEntry()
$searcher.filter=”(&(ObjectClass=user)(samAccountName=$env:username))”
$find = $searcher.FindOne()
$me = $find.GetDirectoryEntry()
$thispc.InvokeSet(“ManagedBy”,$($me.DistinguishedName))
$thispc.SetInfo()
It works when I execute script locally on Windows 8.1 using PowerShell ISE, Managed By attribute of that computer is populated with DN of logged user. But nothing happens when user logs on, gpresult /r shows that GPO is applied but Managed By attribute stays empty. I used script as logon script deployed using GPO.