title: powershell cmdlet in c# - How to access AD objects in ProcessRecord
body: <p>I am writing a Powershell module in C#. Some of the cmdlets process input from Microsofts AD Powershell module. I like to do something like this in Powershell:</p>
  
  <pre><code>Get-ADUser MyUser | New-MyCmdlet
  </code></pre>
  
  <p>So the AD user 'MyUser' is passed to my Cmdlet 'New-MyCmdlet'. MyUser is of type <code>Microsoft.ActiveDirectory.Management.ADUser</code></p>
  
  <p>The c# class would look as follows:</p>
  
  <pre><code>namespace MyCmdlet
  {
  [Cmdlet(VerbsCommon.New, "MyAdUserOperation")]
  public class NewAdUserOperationCmdlet : Cmdlet
  {
      [Parameter(
          Mandatory = true,
          ValueFromPipeline = true,
          ValueFromPipelineByPropertyName = true,
          HelpMessage = "ADUser object from AD to be stored on database.")]
      public object AdUser { get; set; }
  
      protected override void ProcessRecord()
      {
          base.ProcessRecord();
  
          if (AdUser != null)
          {
              // do something with the props, e.g:
              // var dn = AdUser.DistinguishedName;
              // var pwLastSet = AdUser.PasswordLastSet
              // etc.....
          }
      }
  }
  }
  </code></pre>
  
  <p>I declared the input parameter of type <code>object</code> because I do not know how to get <code>ADUser</code> in my project. So I can see a bit more in the debugger.... The commented code shows, what I'd like to do. </p>
  
  <ul>
  <li>Question 1: I do not find an assembly for <code>Microsoft.ActiveDirectory.Management.ADUser</code>. What do I need to add to my project?</li>
  <li>Question 2: If there is no assembly, how can I access all the properties of this ADUser object? In the debugger of VS 2015 I can see all props even all extended. But how can I access them??</li>
  </ul>