Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Adding current logged on user to Managed By attribute of computer

$
0
0

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.


Viewing all articles
Browse latest Browse all 13067

Trending Articles