title: SharePoint User Profile Search
body: <p>Is there a way to search profiles in MOSS from the object model?  I need to search for profiles that have a certain value set on their profile and then perform some action for them. </p>
  
  <p>I need to write some c# code that can search the profiles database and return the matching profiles.   Basically,   </p>
  
  <p>List of Profiles = Select Profiles From Profile Store Where Profile Property Value = SomeValue</p>
  
  <p>I'm trying to avoid the following:</p>
  
  <pre><code> private IEnumerable&lt;UserProfile&gt; SearchProfiles(string value) {
          ServerContext serverContext = ServerContext.GetContext(SPContext.Current.Site);
          UserProfileManager profileManager = new UserProfileManager(serverContext);
          foreach (UserProfile profile in profileManager) {
              if ((string)profile["MyProp"].Value == value) {
                  yield return profile;
              }
          }
      }
  </code></pre>