Creating multiple PSSession sessions incrementally

Welcome Forums General PowerShell Q&A Creating multiple PSSession sessions incrementally

  • This topic has 1 reply, 2 voices, and was last updated 1 week ago by
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #190939
      Participant
      Topics: 1
      Replies: 0
      Points: 12
      Rank: Member

      Hi All,

      I am in the process of creating a dashboard that runs a script to create a new user.

      The script will clear any existing sessions, set the session value to 0 and then create a new session.  When the user creation task occurs and once the account has been completed, the session is disconnected and removed.

      So that a session remains active whilst in use and doesn't get disconnected when a new session is executed, how can i perform a check to see if a session exists and if it does create a new one with the next ID value.

      e.g.  admin A opens sessions and starts creating a new user

      admin B logs on straight after on a different machine and starts to create a new user also

      i would like each admin to have their own session without closing each others session.

      here is an example of my script:``

      $session = $null
      If($session -eq $null){
      $session = 0
      }
      
      Else {$session++}
      
      Disconnect-PSSession $session
      
      Remove-PSSession $session
      

      Will this suffice? Am I going about this the right way?

      Thanks for your feedback.

      Angelo

    • #190948
      Participant
      Topics: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      If you have a cmdlet New-PSSession and Remove-PSSession there's likely a cmdlet Get-PSSession to list the existing PSSessions.

      You should read the complete help for each cmdlet you're about to use ... including the examples to learn how to use it.

      BTW: You can re-connect sessions if you need, you can name them to identify them and you can 'save' sessions in a variable for later use.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.