1

I have computer name = xyz

I run the following script to set usercontrol flag.

$accountName = "xyz";

$user  = [ADSI] "LDAP://CN=xyz,OU=TestOS,DC=domain,DC=net"
Write-Host $user
if(($user.UserAccountControl[0] -band 4096) -ne 0) {
"WORKSTATION_TRUST_ACCOUNT (0x1000 4096) set for $accountName"

} else {

    "WORKSTATION_TRUST_ACCOUNT (0x1000 4096) is NOT set for $accountName"

    # Add the useraccountdisabled flag (decimal value 4096)
    $user.userAccountControl[0] += 4096

    # Save the new value in the user object
    $user.SetInfo()

    "WORKSTATION_TRUST_ACCOUNT (0x1000 4096) has been added for $accountName"
}

but getting output as

Exception calling "SetInfo" with "0" argument(s): "A device attached to the system is not functioning.

I searched and found out if computer name doesn't exit these error will be thrown.

But I am able to get details using following command.

 Get-ADComputer "xyz" -Properties *

Why I am getting "A device attached to the system is not functioning" error even though machine name exist?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Suri
  • 3,287
  • 9
  • 45
  • 75
  • Isn't `$user` supposed to be a *user* and not a *computer* ? – sodawillow Dec 14 '15 at 11:36
  • How can I modify above script to set user control flag for machine name=xyz? – Suri Dec 14 '15 at 12:02
  • As far as I could read, this kind of flags *control the behavior of the Microsoft Active Directory **user** account* – sodawillow Dec 14 '15 at 12:05
  • if you see my question edit section http://stackoverflow.com/questions/34216863/how-to-set-user-account-flag-workstation-trust-account-in-active-directory-using , I am trying to set the flag using C# code but getting access denied. So I am trying to do it with powershell to check if I get same error. Can you help me on this how to sort out this problem. – Suri Dec 14 '15 at 12:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97850/discussion-between-suri-and-sodawillow). – Suri Dec 14 '15 at 12:31
  • any solution ? ***sAMAccountName maxlength*** https://stackoverflow.com/questions/3095510/creating-a-user-in-active-directory-a-device-attached-to-the-system-is-not-func – Kiquenet Jun 13 '18 at 10:48

0 Answers0