title: Should I prefer Export-ModuleMember or the global scope when exposing PowerShell module members?
body: <p>I've been writing a Cmdlet, and, to keep my interfaces clean, I've been manually exporting the functions I care about with <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/export-modulemember?view=powershell-7.1" rel="nofollow noreferrer"><code>Export-ModuleMember</code></a>.</p>
  <p>However, someone pointed out that I could also put my functions directly in the <code>global:</code> <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.1" rel="nofollow noreferrer">scope</a> instead, without calling <code>Export-ModuleMember</code>.</p>
  <p>Which one is preferable?</p>
  <pre><code># Option A: Export-ModuleMember
  function Do-Something {}
  Export-ModuleMember -Function Do-Something
  
  # Option B: global scope
  function global:Do-AnotherThing {}
  
  # Something else?
  </code></pre>
  <p>Thanks!</p>
  <hr />
  <p>My hunch is that <code>Export-ModuleMember</code> is better since it lets the caller decide which scope the function ends up in (e.g. another cmdlet could import my cmdlet without exposing those exported functions globally), but I'm not sure.</p>