title: Add Powershell Snapin for Powershell Module and Import Multiple Times
body: <p>I would like to use the SqlServerCmdletSnapin for my custom Powershell Commandlet I am building.  If I add the following code to the beginning of my PSM1:</p>
  
  <pre><code>if ( (Get-PSSnapin -Name sqlserverprovidersnapin100 -ErrorAction SilentlyContinue) -eq $null )
  {
      Add-PsSnapin sqlserverprovidersnapin100
  }
  
  if ( (Get-PSSnapin -Name sqlservercmdletsnapin100 -ErrorAction SilentlyContinue) -eq $null )
  {
      Add-PsSnapin sqlservercmdletsnapin100
  }
  Export-ModuleMember Invoke-SqlCmd
  </code></pre>
  
  <p>everything works great the first time I run: </p>
  
  <blockquote>
    <p>Import-Module MyModule -Force</p>
  </blockquote>
  
  <p>However, the second time I run:</p>
  
  <blockquote>
    <p>Import-Module MyModule -Force</p>
  </blockquote>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Add-PsSnapin : An item with the same key has already been added.</p>
  </blockquote>
  
  <p>and my code can no longer call Invoke-SqlCmd.  What is the best way to add a powershell snapin to my custom module?</p>