(clixml)
return output
When running a powershell script in execute_cmd (WinRS), the stderr
        stream may contain some clixml. This method will clear it up and
        replace it with the error string it would represent. This isn't done
        by default on execute_cmd for various reasons but people can call it
        manually here if they like.

        :param clixml: The clixml to parse
        :return: A unicode code string of the decoded output
When running a powershell script in execute_cmd (WinRS), the stderr
        stream may contain some clixml. This method will clear it up and
        replace it with the error string it would represent. This isn't done
        by default on execute_cmd for various reasons but people can call it
        manually here if they like.
When running a powershell script in execute_cmd ( WinRS ) the stderr stream may contain some clixml . This method will clear it up and replace it with the error string it would represent . This isn t done by default on execute_cmd for various reasons but people can call it manually here if they like .
def sanitise_clixml(clixml):
        """
        When running a powershell script in execute_cmd (WinRS), the stderr
        stream may contain some clixml. This method will clear it up and
        replace it with the error string it would represent. This isn't done
        by default on execute_cmd for various reasons but people can call it
        manually here if they like.

        :param clixml: The clixml to parse
        :return: A unicode code string of the decoded output
        """
        output = to_unicode(clixml)
        if output.startswith("#< CLIXML"):
            # Strip off the '#< CLIXML\r\n' by finding the 2nd index of '<'
            output = output[clixml.index('<', 2):]
            element = ET.fromstring(output)
            namespace = element.tag.replace("Objs", "")[1:-1]

            errors = []
            for error in element.findall("{%s}S[@S='Error']" % namespace):
                errors.append(error.text)

            output = Serializer()._deserialize_string(u"".join(errors))

        return output
def sanitise_clixml ( clixml ) : output = to_unicode ( clixml ) if output . startswith ( "#< CLIXML" ) : # Strip off the '#< CLIXML\r\n' by finding the 2nd index of '<' output = output [ clixml . index ( '<' , 2 ) : ] element = ET . fromstring ( output ) namespace = element . tag . replace ( "Objs" , "" ) [ 1 : - 1 ] errors = [ ] for error in element . findall ( "{%s}S[@S='Error']" % namespace ) : errors . append ( error . text ) output = Serializer ( ) . _deserialize_string ( u"" . join ( errors ) ) return output