title: How to use domain controller in Server parameter
body: <p>Using PowerShell script, I am getting a valid hostname using the <code>Get-ADDomainController</code> command as following:</p>
  
  <pre><code>$domainController = (Get-ADDomainController -DomainName 'mydomain.local' -Discover).hostname;
  </code></pre>
  
  <p>After having defined my credentials, I would like to use the retrieved hostname in the Server parameter of my <code>Get-ADUser</code> command:</p>
  
  <pre><code>$User = Get-ADUser -Identity 'accountName' -Server $domainController -Credential $mycred;
  </code></pre>
  
  <p>However, the code fails and the prompted error looks like:</p>
  
  <blockquote>
    <p>Cannot convert Microsoft.ActiveDirectory.Management.ADPropertyValueCollection into String</p>
  </blockquote>
  
  <p>Could you please give any insights on how to convert that value into String?</p>