title: Why I am getting "A device attached to the system is not functioning" error even though machine name exist?(Active Directory)
body: <p>I have computer name = xyz</p>
  
  <p>I run the following script to set usercontrol flag.</p>
  
  <pre><code>$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"
  }
  </code></pre>
  
  <p>but getting output as</p>
  
  <blockquote>
    <p>Exception calling "SetInfo" with "0" argument(s): "A device attached to the system is not functioning.</p>
  </blockquote>
  
  <p>I searched and found out if computer name doesn't exit these error will be thrown.</p>
  
  <p>But I am able to get details using following command.</p>
  
  <pre><code> Get-ADComputer "xyz" -Properties *
  </code></pre>
  
  <p>Why I am getting "A device attached to the system is not functioning" error even though machine name exist?</p>