title: How to extend C# DirectoryServices UserContext with msTSProfilePath, msTSHomeDirectory etc
body: <p>I need to read/write ActiveDirectory User object Terminal Services properties.
  I tried this:</p>
  
  <pre><code>PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
  
          using (context)
          {
              UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
              if (user != null)
              {
                  DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
                  entry.Properties["msTSProfilePath"].Value = "";
                  entry.Properties["msTSHomeDirectory"].Value = "";
                  entry.Properties["msTSHomeDrive"].Value = "";
                  entry.CommitChanges();
              }
  
          }
  </code></pre>
  
  <p>And I tried this:</p>
  
  <pre><code>PrincipalContext context = new PrincipalContext(ContextType.Domain, "CA");
  
          using (context)
          {
              UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "CA\\vlekovic");
              if (user != null)
              {
                  DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
                  entry.InvokeSet("msTSProfilePath", "");
                  entry.InvokeSet("msTSHomeDirectory", "");
                  entry.InvokeSet("msTSHomeDrive", "");
                  entry.CommitChanges();
              }
  
          }
  </code></pre>
  
  <p>But nothing works.</p>
  
  <p>I tried also with following property names:</p>
  
  <ul>
  <li>TerminalServicesProfilePath </li>
  <li>TerminalServicesHomeDirectory </li>
  <li>TerminalServicesHomeDrive</li>
  </ul>
  
  <p>But no luck. Any help would be appreciated!</p>
  
  <p>Thanks,
  Vojin</p>