title: Get a list of maibox databases in each DAG
body: <p>I have a need to get a list of databases contained in each DAG but I am struggling to get it. If I use</p>
  
  <pre><code>Get-databaseavailabilitygroup
  </code></pre>
  
  <p>I get a list of the DAGs and the member servers but as soon as I try</p>
  
  <pre><code>Get-databaseavailabilitygroup|get-mailboxdatabase
  </code></pre>
  
  <p>I get an error saying the DAG name can not be found on the DC.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>We have 3 seperate environments each with different database names and a different number of databases. 
  I am trying to get a list of the databases in each DAG as this will be passed into a function that works out which DAG to create the mail account on and then creates the account on the database with the least number of users on it.
  I want to create it this way so I can use the same script across all environments and it will also cater for new databases</p>
  
  <p>TIA</p>
  
  <p>Andy</p>