我正在尝试在我的公司中设置端点服务器并且正在努力连接到它。为了测试,我在全局模块路径中放置了一个 RcLogUtil 模块
C:\windows\system32\WindowsPowershell\v1.0\Modules\RcLogUtil\
导出函数
'Out-LogToEventLog','New-LogMessage'
该计划是让一组特定的用户只访问那些记录功能。
我创建一个 session 配置:
New-PSSessionConfigurationFile -Path C:\Scripts\LoggerEp.pssc `
-SessionType RestrictedRemoteServer `
-LanguageMode FullLanguage `
-ExecutionPolicy Unrestricted `
-ModulesToImport 'RcLogUtil' `
-VisibleFunctions 'Out-LogToEventLog' `
-VisibleCmdlets 'Split-Path'
注册它:
Register-PSSessionConfiguration -Path C:\Scripts\LoggerEp.pssc `
-Name loggerep `
-ShowSecurityDescriptorUI
并在我的本地机器上输入:
[W0216]> Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep
Enter-PSSession : One or more errors occurred processing the module 'RcLogUtil' specified in the InitialSessionState object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was: The term 'Split-Path' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (:) [Enter-PSSession], RunspaceOpenModuleLoadException + FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen
现在最大的问题是.. 为什么 Session 无法找到 Split-Path?或者我如何告诉端点加载那个特定的 cmdlet?
我用 SessionType='Default' 成功地尝试了同样的方法,它可以工作,但是周围有所有的 powershell 困惑。
我真的很感激我能得到的任何帮助,因为我已经坚持了很长一段时间了..
谢谢!
最佳答案
在创建 SessionConfiguration 时,可以选择通过使用 -SessionType Default 和 -ScriptsToProcess 'C:\Scripts\LoggerEpStartup.ps1' 参数来提前禁用每个 cmdlet。
New-PSSessionConfigurationFile -Path C:\Scripts\LoggerEp.pssc `
-SessionType Default `
-LanguageMode FullLanguage `
-ExecutionPolicy Unrestricted `
-ModulesToImport 'RcLogUtil' `
-VisibleFunctions 'Out-LogToEventLog' `
-ScriptsToProcess 'C:\Scripts\LoggerEpStartup.ps1'
C:\Scripts\LoggerEpStartup.ps1:
# Commands needed by PSSession (Also the commands used when
# creating a RestrictedRemoteServer )
$CmdsToExclude = @(
'Get-Command' , 'Out-Default' ,
'Exit-PSSession', 'Measure-Object',
'Select-Object' , 'Get-FormatData'
)
# Hide any other commandlets except the ones needed
# to create a remote session
Get-Command | Where Visibility -eq 'Public' | ForEach-Object {
if ( $_.Name -notin $CmdsToExclude ) {
$_.Visibility = 'Private'
}
}
但我想避免这种方法,因为它似乎是一种笨拙的解决方法,而不是适当的解决方案。
关于powershell - Enter-PSSession 到自定义端点 : Cmdlet not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18656804/