title: Powershell erroring out of invoke-command with network connection could not be found
body: <p>Since I find answers to most of my questions on this site, I'm hoping someone has my answer tucked away in the recesses of their brain cells and is willing to extract it for me.  I have searched this site and the internet and have not had any success.  Here's the situation.</p>
  
  <p>I'm executing a Powershell script on ServerA that looks like this:</p>
  
  <pre><code>"Creating a Session"
  $session = New-PSSession –ComputerName $machine -authentication credssp -credential $cred -Name Upgrade
  ""
  "Launching upgrade installation on $Machine"
  Invoke-Command -session $session -ScriptBlock {param ($mc, $un, $pw) powershell.exe -executionPolicy bypass c:\PXInstall\AutoUpdate.ps1 -Machine $mc -userName $un -password $pw} -ArgumentList $Machine, $DomainAccount, $DomainAccountPassword
  ""
  "Closing Session"
  $rmSession = get-pssession -name Upgrade
  #remove-pssession -session $session
  remove-pssession -session $rmSession
  </code></pre>
  
  <p>The remote script is an installation powershell script that does a bunch of stuff to install our software.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>As soon as the autoupdate.ps1 file exits it drops to my catch block with the error <strong><em>"The network connection could not be found"</em></strong>.  </p>
  
  <p>If I output all the errors that are showing after the setup script runs (still in autoupdate.ps1).  There are 8 errors, none of which say the network connection could not be found. </p>
  
  <p>Before autoupdate.ps1 script exits I do an $error.clear() hoping to not have it return with an error, but it still does.  The error in position 0 of the error list is "Exception calling "Add" with "1" argument(s): the specified account name is already a member of the group."</p>
  
  <p>So it seems like something the install script is doing is causing the invoke-command to return with an error.  Any ideas how to clear that error so the script returns normally, other than $error.clear() since that isn't working.  I want legitimate errors thrown in the install script to bubble up from the install script into the main script so I can act accordingly.</p>
  
  <p>---edited for brevity after figuring stuff out---</p>