0

Code

$PGroup = Invoke-Command -ComputerName "xx.example.net" -ScriptBlock {Get-DPMProtectionGroup -DPMServerName "xx.example.net" | ft name -HideTableHeaders}
    Invoke-Command -ComputerName "xx.example.net" -ScriptBlock {Get-DPMJob -ProtectionGroup $PGroup -Status Failed}

Error :-

Cannot validate argument on parameter 'ProtectionGroup'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + CategoryInfo : InvalidData: (:) [Get-DPMJob], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Internal.EnterpriseStorage.Dls.UI.Cmdlet.GetDpmJobCmdlet

Theo
  • 57,719
  • 8
  • 24
  • 41
  • 1
    Remove `| ft name -HideTableHeaders` and in the line below do `-ProtectionGroup ($using:PGroup).Name`. The `Format-*` cmdlets are for **display on screen purposes only**. You should not use them if you want to process the variable any further – Theo May 02 '22 at 14:03
  • Theo's point is also worth heeding (elaborated on in the 2nd linked duplicate), but the primary problem is that you need the `$using:` scope in order to reference the value of a _local_ variable in _remote_ call - see the 1st linked duplicate. – mklement0 May 02 '22 at 14:41

1 Answers1

0

Format-table converts your object for display in the terminal, but you don't want that if you're using it downstream for another purpose.

OwlsSleeping
  • 1,487
  • 2
  • 11
  • 19
  • While that is also a good point, note that the primary problem, as implied by the error message, is the attempt to access a _local_ variable in a _remote_ script block withou the `$using:` scope. – mklement0 May 02 '22 at 17:08