且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell远程处理:使用Powershell远程配置文件中加载的功能吗?

更新时间:2022-12-06 13:37:48

在默认会话配置中使用pssessions时,不会运行任何配置文件脚本.如果要预配置会话(以加载自定义功能,管理单元,模块...),请向新的 sessionconfiguration 添加配置文件脚本. Register-PSSessionConfiguration cmdlet在本地创建并注册新的会话配置电脑.使用 Get-PSSessionConfiguration 查看现有的会话配置. Get-PSSessionConfiguration和Register-PSSessionConfiguration都需要提升的权限(使用以管理员身份运行"选项启动PowerShell).

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

(其中$ computername是您注册pssessionconfiguration的RemoteServer的主机名).

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

《 Powershell Remoting管理员指南》 是有关Powershell Remoting的一个很好的资料.

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