[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44
  • Last Modified:

How to find out, if a remote Session has allready been imported

When we import-pssession, Poweshell creates a temporary module for implicit remoting. When we remove-pssession, all the temporary modules that belong to it (Powershell creates a new module every time we Import the session!) are removed.

My goal is to know, if a certain PSSession has been already imported or not. The idea was to find out, if there are modules bound to this session. Unfortunately I could not find any properties in modules that would reference the session neither the session properties referencing the modules. But Powershell knows it somehow!

Does anyone have an idea?

Thanks
Alexander Lerner
0
AlLerner
Asked:
AlLerner
  • 4
  • 3
  • 3
2 Solutions
 
FOXActive Directory/Exchange EngineerCommented:
run the command Get-PSSession to see which sessions are connected to the local computer
run the command Get-PSSessionConfiguration to see the registered session configurations on the local computer
0
 
AlLernerAuthor Commented:
Unfortunately it does not solve the Problem. Please read the question again. Thank you.
0
 
FOXActive Directory/Exchange EngineerCommented:
The command Get-Module will show you all modules you have on your session
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
AlLernerAuthor Commented:
Thank you. On which session? I am still in my local session, but I have imported a remote-session and now I look for indices, that a certain remote session has already been imported.
0
 
FOXActive Directory/Exchange EngineerCommented:
using Get-PSSession will show you all sessions on your local machine.  Each session has an ID/guid number. from there you can use a
Connect-PSSession IDNumber

in your powershell run a get-help Get-PSSession -detailed  (for syntax)  
Also run get-help PSSession -detailed                               (for more commands)
0
 
AlLernerAuthor Commented:
Dear Foxluv... Please, read my question. I don't want to know the ID of the session. I don't want to connect to session because it has never been disconnected. I want to know, if the session has been imported!!!!!!
0
 
footechCommented:
If you look at a module's Description property you can see that it includes the name of the server that it's connected to for implicit remoting.   I suppose you could do a check on a PsSession's ComputerName property to see if any modules have a Description property that includes the computer name.

If you have PS 3.0+, you might consider using Import-Module <modulename> -PsSession $s
In this case, even if the session $s is removed, if you try to run on of the commands from the imported module, it will automatically try to reestablish a session for the implicit remoting.
0
 
AlLernerAuthor Commented:
Well, it is not exactly what I would like to use, because Microsoft can change the description of such module any time it likes, somewhere between the release 5 and 6. Mor than that, the description is in the language of OS, so it can be tricky to look, where exactly in is the URI (not actually the server name) of the session to look for. But there is likely nothin else one could actually use.
0
 
footechCommented:
The temp modules are saved to the filesystem.  If you actually look in the module file, you can find the InstanceID of the PsSession.
Get-PSSession | Where { Select-String -path (Get-Module | Select -expand path) -pattern $_.instanceid.tostring() -simplematch }

Open in new window


I don't know if this will work for all use cases.
It might be better if you state what problem you're trying to solve, or even why you're trying to solve it.  Perhaps a better approach could be suggested.
0
 
footechCommented:
ID: 41769351 provides a method that will work for at least some circumstances.
ID: 41774352 provides a method that is more reliable.
0

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now