0

Do i get it right that when i have a Profile on a RemoteServer which loads some functions, these functions should be available in a Remote PSSession?

My tests weren't successfull, is there a special trick to get this working?

I want to refer to Folder on a network share to have all Functions on a single source available.

icnivad
  • 2,231
  • 8
  • 29
  • 35

1 Answers1

7

When you use pssessions with the default session configurations, no profile scripts run. If you want a session to be preconfigured (to load custom functions, snap-ins, modules ...), add a profile script to a new sessionconfiguration. The Register-PSSessionConfiguration cmdlet creates and registers a new session configuration on the local computer. Use Get-PSSessionConfiguration to view existing session configurations. Both Get-PSSessionConfiguration and Register-PSSessionConfiguration require elevated rights (start PowerShell with the “Run as Administrator” option).

Register-PSSessionConfiguration -Name WithProfile -StartupScript $PsHome\Profile.ps1

To use this preconfigured session you would type:

Enter-PSSession -ComputerName $computername -ConfigurationName WithProfile

(where $computername is the hostname of RemoteServer where you registered the pssessionconfiguration).

A good source on powershell remoting is the Administrator's Guide to Powershell Remoting.

jon Z
  • 15,838
  • 1
  • 33
  • 35
  • When starting a remote interactive session with enter-pssession, a remote profile is loaded. Additionally, only the machine-level profile in $pshome is loaded. If you want remote functions available you'll have to initialize them in the startup script of the remote session configuration. Have a look at get/set-pssessionconfiguration on the remote server. http://stackoverflow.com/a/2985127/206730 – Kiquenet Feb 21 '13 at 07:54
  • what took me awhile to realize is that you need to do 'register/set-pssessionconfiguration' on the remote machine, not the local one – ErikW Aug 05 '22 at 17:19