title: Exit not Exiting in invoke-command in remote ps session
body: <p>I have a Function invokes a command that starts a new ps session on a remote server. The invoke command has an Exit clause however this is not exiting?</p>
  
  <pre><code>Function CreateID{
  
    Invoke-Command -Session $Script:sesh -ScriptBlock{
      Set-Location c:\
      Import-Module ActiveDirectory
  
      Try
      {
          If (Get-ADGroupMember "$Using:IDGroup" | Where-Object Name -match 
      "$Using:Computer")
          {
              Write-Host "Already in $using:IDGroup Exiting Script"
              Disconnect-PSSession -Session $Script:sesh
              Exit-PSSession
              Exit
          }
       }
       Catch
       { }
       Write-Host "Did not Exit"
  
  
      }
  
  }
  </code></pre>
  
  <p>The Get-AD command works fine so where it should not display "did not exit" it does - how can i exit from a scriptblock in a remote ps session?</p>
  
  <p>I am trying the disconnect session and Exit-pssession to see if they would do the same as simply exit but none of those are working.</p>
  
  <p>I have also tried Break and no luck. </p>