質問

こちらのサンプルスクリプトをつくろうというリモートセッションサーバーを使用し、WMIの一覧を取得するため、サーバのIIS用プールのほか、リストの氏名:

    function Test-Remoting
    {
        [CmdletBinding()]
        param
        (    
        )
        begin
        {
            Enter-PSSession TestServer
            $appPools = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" -Authentication 6
            $appPools | ForEach-Object {
                $appPool = $_;
                $appPool.Name
            }
            Exit-PSSession
        }    
    }

この機能はファイルにまとめられていますという試験-リモ.ps1." 私は開PowerShell、CDのディレクトリを含む、このファイルド-ソースファイル、通話機能:

PS C:\Users\moskie> . .\Test-Remoting.ps1
PS C:\Users\moskie> Test-Remoting

その結果、このスクリプトのリスト用プールも 機械、 ない TestServer.

さくなければなりません。実行し、以下のラインと同一のものの機能を手動でユー迅速ない 一覧の取得をアプリのプールをリモートサーバー:

PS C:\Users\moskie> Enter-PSSession TestServer
[TestServer]: PS C:\> $appPools = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" -Authentication 6
[TestServer]: PS C:\> $appPools | ForEach-Object { $appPool = $_; $appPools.Name }
<a list of the names of the application pools on TestServer>
[TestServer]: PS C:\>

いと思ってい概念が私に無頓着に関して、ユーリモ及ぼす可能性があります。-誰でもできるので理解する上で有効なものについて本的に振る舞えるのでしょうか?

役に立ちましたか?

解決

私の出入り-PSSessionは、インターラクティブに利用します。からの入力-PSSessionヘルプ

SYNOPSIS
    Starts an interactive session with a remote computer.

スクリプトで、新PSSessionを起動コマンドはこのように:

$session = New-PSSession server01
Invoke-Command -Session $session {hostname}
Remove-PSSession -Session $session

更新: を実行する完了スクリプトの遠隔利用のFilePathパラメータを呼び出すコマンド:

icm server01 -FilePath C:\users\keith\myscript.ps1 -arg 1,2

このままコピーするスクリプトへのリモートコンピュータserver01実行することができあり付属のパラメータ。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top