How to use the pypsrp.complex_objects.PipelineResultTypes function in pypsrp

To help you get started, we’ve selected a few pypsrp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_to_string_null(self):
        result_type = PipelineResultTypes(value=PipelineResultTypes.NULL)
        expected = "Null"
        actual = str(result_type)
        assert actual == expected
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_to_string_multiple_values_protocol_v2(self):
        result_type = PipelineResultTypes(protocol_version_2=True, value=3)
        expected = "Output, Error"
        actual = str(result_type)
        assert actual == expected
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_to_string_all(self):
        result_type = PipelineResultTypes(value=PipelineResultTypes.ALL)
        expected = "All"
        actual = str(result_type)
        assert actual == expected
github jborean93 / pypsrp / tests / test_complex_objects.py View on Github external
def test_to_string_one_value(self):
        result_type = PipelineResultTypes(value=1)
        expected = "Output"
        actual = str(result_type)
        assert actual == expected
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
def _set_merge_to(self, merge, to, valid, min_protocol=None):
        valid = valid or ["none", "null", "output"]
        if to not in valid:
            raise InvalidPSRPOperation("Invalid merge to option '%s', valid "
                                       "values %s" % (to, ", ".join(valid)))

        if min_protocol is not None:
            if not version_equal_or_newer(self.runspace_pool.protocol_version,
                                          min_protocol):
                error_msg = \
                    "Merge option for '%s' is not supported in the current " \
                    "protocol version %s, minimum version required %s" % \
                    (merge, self.runspace_pool.protocol_version, min_protocol)
                raise InvalidPSRPOperation(error_msg)

        to_value = getattr(PipelineResultTypes, to.upper())
        to_result = PipelineResultTypes(value=to_value)
        setattr(self._current_command, merge, to_result)
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
def merge_previous(self, enabled=False):
        """
        Sets the MergePreviousResults of the last command in the pipeline.
        This is the same as the MergeUnclaimedPreviousCommandResults property
        used in the .NET System.Management.Automation.Runspaces.Command class.

        :param enabled: Whether to merge previous results to the Output and
            Error streams or not
        :return: The current PowerShell instance with the last command set to
            MergePreviousResults
        """
        if enabled:
            value = PipelineResultTypes.OUTPUT | PipelineResultTypes.ERROR
        else:
            value = PipelineResultTypes.NONE
        pipeline = PipelineResultTypes(protocol_version_2=True, value=value)
        self._current_command.merge_previous = pipeline
        return self
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
valid = valid or ["none", "null", "output"]
        if to not in valid:
            raise InvalidPSRPOperation("Invalid merge to option '%s', valid "
                                       "values %s" % (to, ", ".join(valid)))

        if min_protocol is not None:
            if not version_equal_or_newer(self.runspace_pool.protocol_version,
                                          min_protocol):
                error_msg = \
                    "Merge option for '%s' is not supported in the current " \
                    "protocol version %s, minimum version required %s" % \
                    (merge, self.runspace_pool.protocol_version, min_protocol)
                raise InvalidPSRPOperation(error_msg)

        to_value = getattr(PipelineResultTypes, to.upper())
        to_result = PipelineResultTypes(value=to_value)
        setattr(self._current_command, merge, to_result)
github jborean93 / pypsrp / pypsrp / complex_objects.py View on Github external
2: 'Error',
                3: 'Output, Error',
            }
        else:
            string_map = {
                0: 'None',
                1: 'Output',
                2: 'Error',
                3: 'Warning',
                4: 'Verbose',
                5: 'Debug',
                6: 'Information',
                7: 'All',
                8: 'Null',
            }
        super(PipelineResultTypes, self).__init__(
            "System.Management.Automation.Runspaces.PipelineResultTypes",
            string_map, **kwargs
        )
github jborean93 / pypsrp / pypsrp / powershell.py View on Github external
Controls where the Error stream of the last command in the pipeline
        will be sent to.

        :param to: Can be one of the following
            none: Send all Error streams to the Error stream
            output: Send all Error streams to the Output stream
        :return: The current PowerShell instance with the last command set to
            MergeError to the stream desired.
        """
        self._set_merge_to("merge_error", to, ["none", "output"])

        # For V2 backwards compatibility
        if to == "none":
            my_result = self._current_command.merge_error
        else:
            my_result = PipelineResultTypes(value=PipelineResultTypes.ERROR)
        self._current_command.merge_my_result = my_result
        self._current_command.merge_to_result = \
            self._current_command.merge_error
        return self