7
votes

I'm writing a Powershell Cmdlet for which I need to pass in a PSRemotingJob object as a parameter. The MCVE follows:

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

    BEGIN {}

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

    END {}
}

The issue is that when I pass a job into the cmdlet, I get an error, as follows:

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>

I realize that this should be a simple matter of substituting the correct object type or fully-qualified object, but I've also tried using [System.Management.Automation.PSRemotingJob] with the same results.

I'm using Powershell 4.0.

1
System.Management.Automation.PSRemotingJob is internal type. You can not express it in PowerShell type syntax.user4003407
Thanks. Just changing $Job to an untyped variable did the trick. If you'd put that into a regular answer, I'd be glad to give you the up-check and the solution credit.Deacon

1 Answers

11
votes

System.Management.Automation.PSRemotingJob is not public type and thus can not be expressed in PowerShell type syntax. But you can use its base public type instead: [System.Management.Automation.Job].