title: c# Bitlocker information from Active Directory
body: <p>I'm trying to get bit locker recovery information for all users from active directory via below functions.
  I've tried many different solution but none of them solved my problem. 
  I can get most of the computer properties like Operation System,Service Pack expect bit locker info.
  Is there any special permission or method to search with msFVE-RecoveryInformation ?</p>
  
  <p>Method 1:</p>
  
  <pre><code> DirectoryEntry child = new DirectoryEntry("LDAP://XXXXX");
          DirectoryEntries enteries = child.Children;
          DirectorySearcher ds = new DirectorySearcher(child);
          ds.Filter = "(&amp;(objectCategory=Computer)(cn=computerName))";
          ds.SearchScope = SearchScope.Subtree;
          SearchResultCollection item = ds.FindAll();
  
          //string dn = item.GetDirectoryEntry().Properties["distinguishedname"].Value.ToString();
          string temp1 = System.DirectoryServices.AccountManagement.UserPrincipal.Current.DistinguishedName;
          child = new DirectoryEntry(("LDAP://" + temp1), "XXXXX", "XXXXX");
          enteries = child.Children;
          ds = new DirectorySearcher(child);
          ds.Filter = "(objectClass=msFVE-RecoveryInformation)";
          ds.SearchScope = SearchScope.Subtree;
  
          SearchResultCollection result = ds.FindAll();
  
          if (result.Count &gt; 0)
          {
              foreach (SearchResult sr in result)
              {
                  string recoveryKeyPackage = sr.GetDirectoryEntry().Properties["msFVE-KeyPackage"].Value.ToString();
                  string recoveryGUID = sr.GetDirectoryEntry().Properties["msFVE-RecoveryGuid"].Value.ToString();
                  string recoveryPassword = sr.GetDirectoryEntry().Properties["msFVE-RecoveryPassword"].Value.ToString();
                  string recoveryVolumeGUID = sr.GetDirectoryEntry().Properties["msFVE-VolumeGuid"].Value.ToString();
              }
          }
          else
          {
             Console.Write ("No recovery information found!");
          } 
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code> public Dictionary&lt;string, string&gt; GetBitlockerKeys(string computerName)
      {
          DirectoryEntry dEntry = new DirectoryEntry("LDAP://XXXX");
          var keys = new Dictionary&lt;string, string&gt;();
          using (var computerObject = dEntry)
          {
              var children = computerObject.Children;
              var schemaFilter = children.SchemaFilter;
              schemaFilter.Add("msFVE-RecoveryInformation");
              foreach (DirectoryEntry child in children) using (child)
                  {
                      var recoveryGuid = new Guid((byte[])child.Properties["msFVE-RecoveryGuid"].Value).ToString();
                      var recoveryPassword = child.Properties["msFVE-RecoveryPassword"].Value.ToString();
                      if (!keys.ContainsKey(recoveryGuid))
                      {
                          keys.Add(recoveryGuid, recoveryPassword);
                      }
                  }
          }
  
          return keys;
      }
  </code></pre>