0

I need to call a script, which gets the status of the last backup (Get-WBJob -Previous 1) and use attribute HResult (will be 0 or 1) in the next step.

Example returned object from Get-WBJob

I have:

$params = @{"ID"="811185195";
            "Server"="XAD";
            "success"="Here i need have result of HResult"}

How do I get the only the HResult property from Get-WBJob?

codewario
  • 19,553
  • 20
  • 90
  • 159
  • Depends on the object type. Maybe append `|Select-Object -ExpandProperty hresult` and write that to a variable – An-dir May 18 '22 at 13:57
  • See also: [Select the values of one property on all objects of an array in PowerShell](https://stackoverflow.com/a/48888108/1701026) – iRon May 18 '22 at 14:13

1 Answers1

1

You can use the grouping operator () (formerly called the group-expression operator) to operate on the returned object by the grouped expression. For example:

$hResult = ( Get-WBJob -Previous 1 ).HResult

You can assign this to a variable as shown above, or simply set the result of the expression in the Hashtable itself:

$params = @{
  ID     = "811185195"
  Server = "XAD"
  Success = ( Get-WBJob -Previous 1 ).HResult
}

Alternatively, you can use Select-Object -ExpandProperty as well, instead of wrapping the inner expression in parentheses:

Get-WBJob -Previous 1 | Select-Object -ExpandProperty HResult
codewario
  • 19,553
  • 20
  • 90
  • 159