2

会社でエンドポイント サーバーをセットアップしようとしていますが、接続に苦労しています。 テストのために、関数をエクスポートするグローバル モジュール パス
C:\windows\system32\WindowsPowershell\v1.0\Modules\RcLogUtil\に 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 : この実行空間の作成に使用された InitialSessionState オブジェクトで指定されたモジュール 'RcLogUtil' の処理中に 1 つ以上のエラーが発生しました。エラーの完全なリストについては、ErrorRecords プロパティを参照してください。最初のエラー: 「Split-Path」という用語は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前のスペルを確認するか、パスが含まれている場合は、パスが正しいことを確認してから再試行してください。行:1 文字:1 + Enter-PSSession -ComputerName mka-ps-endpoint -ConfigurationName loggerep + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OpenError: (:) [Enter-PSSession]、RunspaceOpenModuleLoadException + FullyQualifiedErrorId : ErrorLoadingModulesOnRunspaceOpen

大きな問題は、なぜセッションが分割パスを見つけられないのかということです。または、その特定のコマンドレットをロードするようにエンドポイントに指示するにはどうすればよいですか? 私は SessionType='Default' で同じことを試してみましたが、うまくいきましたが、その周りにすべてのパワーシェルが散らかっていました。


私はこれでかなり長い間立ち往生しているので、私が得ることができる助けを本当に感謝します..ありがとう!

4

1 に答える 1

0

SessionConfiguration の作成時に-SessionType Default-ScriptsToProcess 'C:\Scripts\LoggerEpStartup.ps1'パラメータと共に使用して、事前に各コマンドレットを無効にするオプションがあります。

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'
    }
}

しかし、適切な解決策というよりも不器用な回避策のように思われるため、そのアプローチは避けたいと思います。

于 2013-09-06T14:21:29.203 に答える