Powershell Remoting: Use Functions loaded in Powershell remote Profile? [duplicate]

大城市里の小女人 提交于 2019-12-25 08:28:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!