A hashTable is initialized with various parameters. Keys are set to the same values as the -ComputerName parameter of the "New-PSSession" commandlet.
Within the script block (Invoke-Command), we use the hashTable to retrieve the server-specific value based on the "$env:COMPUTERNAME" value.
Here, the code assumes that the supplied name of the server will be the same as the value of "$env:COMPUTERNAME".... For example, if someone pass the fully qulified name of the server, our code will not work.
When a session is created, a session ID is assigned. We could use the "session ID" to create a link between the session and our server-specific configuration entry.
Is there a way to retrieve the "Session ID" of the "current session" within the "Invoke-Command". So our code could look like thie
Hey @michelloubier, short answer is to check out the $PSSenderInfo variable.
$PSSenderInfo is an automatic variable that only exists inside a PSSession and gives you a bunch of info about the session and the originating connection source.
The property inside that variable that will be of the most help is the Connection String:
This tells you a lot about the connection, including the port used, but the key here is that the host name matches the name supplied when opening the connection. As an example here's the output and how it changes when connecting to my home server by name vs by IP address: