2016-06-23 14 views
2

私はPSRemotingJob オブジェクトをパラメータとして渡す必要があるPowershellコマンドレットを作成しています。 MCVEは、次のとおりです。Powershell 4.0でPSRemotingJobオブジェクトをパラメータとして渡す

function My-Cmdlet { 
    [CmdletBinding()] 
    Param(
     [Parameter(Position=0, 
        Mandatory=$true, 
        ValueFromPipeline=$true, 
        ValueFromPipelineByPropertyName=$true)] 
     [PSRemotingJob[]]$Job 
    ) 

    BEGIN {} 

    PROCESS { 
     ForEach ($j in $Job) { 
      $j 
     } 
    } 

    END {} 
} 

問題は、私はコマンドレットに仕事を渡す際に、次のように、私は、エラーを取得することです:

PS C:\Temp> Invoke-Command -AsJob -CN svr001 -Command {Start-Sleep 10} | My-Cmdlet 
My-Cmdlet : Unable to find type [PSRemotingJob]. Make sure that the assembly that contains this type is loaded. 
At line:1 char:63 
+ Invoke-Command -AsJob -CN svr001 -Command {Start-Sleep 10} | My-Cmdlet 
+                ~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (PSRemotingJob:TypeName) [], RuntimeException 
    + FullyQualifiedErrorId : TypeNotFound 

PS C:\Temp> 

私は、これは置き換えの単純な問題であることを実感します正しいオブジェクト タイプまたは完全修飾オブジェクトですが、私も [System.Management.Automation.PSRemotingJob]を使って同じ結果を試しました。

私はPowershell 4.0を使用しています。

+0

'System.Management.Automation.PSRemotingJob'は内部型です。 PowerShell型の構文では表現できません。 – PetSerAl

+0

ありがとうございます。 '$ Job'をタイプのない変数に変更するだけで、このトリックができました。それを普通の答えに入れるなら、私はあなたにアップチェックとソリューションクレジットを与えることをうれしく思います。 –

答えて

3

System.Management.Automation.PSRemotingJobはパブリック型ではないため、PowerShell型の構文では表現できません。しかし、代わりにその基本パブリックタイプを使用することができます:[System.Management.Automation.Job]

関連する問題