title: Conditional loading of snapins in profile
body: <p>We have an internal application that utilizes PowerShell.  In my profile (Microsoft.PowerShell_profile.ps1) I have added references to various snap-ins that we've created:</p>
  
  <pre><code>#
  # Profile for Joe Blow
  #
  Add-PSSnapIn CompanySnapin
  Add-PSSnapin PowerShellTestTools
  Add-PSSnapin SqlServerCmdletSnaps -ErrorAction SilentlyContinue
  </code></pre>
  
  <p>The problem I'm having is that when I start this internal application, the above lines of code, throw errors.</p>
  
  <p>My question is, is there a way (in my profile script) where I can test WHO or WHAT is trying to open the profile and do things accordingly ?</p>
  
  <p>Example might be:</p>
  
  <pre><code>if (!internalApplication)
  {
      Add-PSSnapIn CompanySnapin
      Add-PSSnapin PowerShellTestTools
      Add-PSSnapin SqlServerCmdletSnaps -ErrorAction SilentlyContinue
  }
  </code></pre>
  
  <p>so I get the snapins if I launch the PowerShell command line utility.  Otherwise, nothing is "added".</p>
  
  <p>Thanks !</p>