1

We have a powershell script that download data from an url, verify the data using some generic and simple rules and return success or failed (0 or 1). Here is an example

Get-data -uri "http://www.google.com/some_path"

This script is used successfully in many situations. However, in some cases the simple rules implemented in the Get-data script is not enough to verify the data. We do not want to add a lot of domain specific rules into the Get-data. It would be much better if the parent script performed the additional verification but then it needs access to the raw data. How can we return both a boolean return value of success \ failed and a data object?

1 Answer 1

1

How about returning an object instead of a bool:

$props = @{
  Success = $result
  Data = $theData
}
$object = new-object psobject -Property $props
return $object

You can get the object like so:

$result = Get-data -uri "http://www.google.com/some_path"
if($result.success) {
    # Do all the stuff you want with $result.data
}

Read more about creating objects here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.