I've been playing around with New-PSSession for several computerNames and setting them up in a variable ($DCs)
I can retrieve those Sessions fine with Get-Sessions and then, wanted to remove those sessions altogether (close and then free up the variable) so I used Remove-PSSessions $DCs. It seemed to work.
But when I repeat the New-PSSession for the same variable, I get a whole new set of session IDs (incremented sequentially)
So, then I thought I would just clear and/or remove the variable $DCs altogether and that doesn't seem to work. I get no error with with either clear-variable $DCs or remove-variable $DCs yet, $DCs persists within my PS ISE admin console.
1) I wish to generate new PS-Sessions using the same earlier session IDs (helps me understand PSSession)
2) I wish to understand why I can't get rid of a manually defined variable name that persists (get-variable $DCs) without closing the shell.
When you run scripts by pressing the "Run" button (or pressing F5) in the ISE, it behaves a lot like you had dot-sourced a script at the powershell.exe prompt. Variables in the script's top scope will persist in the global session.
You'll probably wind up with new session IDs every time you call New-PSSession; it shouldn't matter if they match whatever you had on a previous execution.