【问题标题】:Enter-PSSession to custom endpoint: Cmdlet not recognizedEnter-PSSession 到自定义端点:无法识别 Cmdlet
【发布时间】:2013-09-10 11:55:08
【问题描述】:

我正在尝试在我的公司中设置一个 Endpoint-Server,并且正在努力连接它。为了进行测试,我在全局模块路径中放置了一个 RcLogUtil 模块
C:\windows\system32\WindowsPowershell\v1.0\Modules\RcLogUtil\
导出函数

'Out-LogToEventLog','New-LogMessage'

计划是让一组特定的用户只访问那些日志记录功能。

我创建了一个 SessionConfiguration:

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 : 处理模块时出现一个或多个错误 'RcLogUtil' 在用于创建的 InitialSessionState 对象中指定 这个运行空间。请参阅 ErrorRecords 属性以获取完整列表 错误。第一个错误是:无法识别术语“拆分路径” 作为 cmdlet、函数、脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证 路径正确,然后重试。在行:1 字符:1 + Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (:) [Enter-PSSession], RunspaceOpenModuleLoadException + FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen

现在最大的问题是.. 为什么 Session 无法找到 Split-Path?或者我如何告诉端点加载那个特定的 cmdlet? 我用 SessionType='Default' 成功地尝试了同样的方法,它可以工作,但是周围有所有的 powershell 混乱。


我真的很感激我能得到的任何帮助,因为我已经坚持了很长一段时间了.. 谢谢!

【问题讨论】:

    标签: powershell scripting powershell-remoting endpoints


    【解决方案1】:

    有一个选项可以提前禁用每个 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'
        }
    }
    

    但我想避免这种方法,因为它似乎是一种笨拙的解决方法,而不是适当的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2016-10-22
      • 2019-08-27
      • 2016-01-30
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多