问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/8860944/powershell-remoting-use-functions-loaded-in-powershell-remote-profile