title: PowerShell InvokeGet the directory property cannot be found
body: <p>We needed to retrieve the information in active directory concerning 'Terminal Services'. For this I've created a function that works fine most of the time. However, with some users we have issues.</p>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>Function Get-ADTSProfile {
                 [CmdletBinding()]
              Param(
                  [Parameter(Mandatory=$true,Position=0)]
                  [String] $DistinguishedName,
                  [parameter(Mandatory=$true,Position=1)]
                  [ValidateNotNullOrEmpty()]
                  [ValidateSet('UserProfile','AllowLogon','HomeDirectory','HomeDrive')]
                  [String]$Property
              )
              Begin {
                  $User = [ADSI]"LDAP://$DistinguishedName"
              }
              Process {
                  Switch ($Property) {
                      'AllowLogon'    {if ($($User.psbase.InvokeGet('allowLogon')) -eq '1'){$True}else{$False}}
                      'HomeDirectory' {$User.psbase.InvokeGet('TerminalServicesHomeDirectory')}
                      'HomeDrive'     {$User.psbase.InvokeGet('TerminalServicesHomeDrive')}
                      'UserProfile'   {$User.psbase.InvokeGet('TerminalServicesProfilePath')}
                  }   
              }
          }
  </code></pre>
  
  <p><strong>The error:</strong></p>
  
  <pre><code>Get-ADTSProfile -DistinguishedName 'CN=test\, test (Den Bosch) NLD,OU=Users,OU=Disabled,OU=NLD,OU=EU,DC=domain,DC=net' -Property 'UserProfile'
  Exception calling "InvokeGet" with "1" argument(s): "The directory property cannot be fo
  und in the cache.
  "
  At S:\Test\Brecht\Testie.ps1:84 char:38
  +                     'UserProfile'   {$User.psbase.InvokeGet('TerminalServicesPro ...
  +                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodTargetInvocation
  </code></pre>
  
  <p>I can't really figure out why it works on some and not on all..</p>