(self, script, configuration_name=DEFAULT_CONFIGURATION_NAME,
                   environment=None)
return "\n".join(powershell.output), powershell.streams, \
               powershell.had_errors
Executes a PowerShell script in a PowerShell runspace pool. This uses
        the PSRP layer and is designed to run a PowerShell script and not a
        raw executable.

        Because this runs in a runspace, traditional concepts like stdout,
        stderr, rc's are no longer relevant. Instead there is a output,
        error/verbose/debug streams, and a boolean that indicates if the
        script execution came across an error. If you want the traditional
        stdout/stderr/rc, use execute_cmd instead.

        :param script: The PowerShell script to run
        :param configuration_name: The PowerShell configuration endpoint to
            use when executing the script.
        :param environment: A dictionary containing environment keys and
            values to set on the executing script.
        :return: A tuple of
            output: A unicode string of the output stream
            streams: pypsrp.powershell.PSDataStreams containing the other
                PowerShell streams
            had_errors: bool that indicates whether the script had errors
                during execution
Executes a PowerShell script in a PowerShell runspace pool. This uses
        the PSRP layer and is designed to run a PowerShell script and not a
        raw executable.
Executes a PowerShell script in a PowerShell runspace pool . This uses the PSRP layer and is designed to run a PowerShell script and not a raw executable .
def execute_ps(self, script, configuration_name=DEFAULT_CONFIGURATION_NAME,
                   environment=None):
        """
        Executes a PowerShell script in a PowerShell runspace pool. This uses
        the PSRP layer and is designed to run a PowerShell script and not a
        raw executable.

        Because this runs in a runspace, traditional concepts like stdout,
        stderr, rc's are no longer relevant. Instead there is a output,
        error/verbose/debug streams, and a boolean that indicates if the
        script execution came across an error. If you want the traditional
        stdout/stderr/rc, use execute_cmd instead.

        :param script: The PowerShell script to run
        :param configuration_name: The PowerShell configuration endpoint to
            use when executing the script.
        :param environment: A dictionary containing environment keys and
            values to set on the executing script.
        :return: A tuple of
            output: A unicode string of the output stream
            streams: pypsrp.powershell.PSDataStreams containing the other
                PowerShell streams
            had_errors: bool that indicates whether the script had errors
                during execution
        """
        log.info("Executing PowerShell script '%s'" % script)
        with RunspacePool(self.wsman, configuration_name=configuration_name) as pool:
            powershell = PowerShell(pool)

            if environment:
                for env_key, env_value in environment.items():
                    # Done like this for easier testing, preserves the param order
                    log.debug("Setting env var '%s' on PS script execution" % env_key)
                    powershell.add_cmdlet('New-Item'). \
                        add_parameter('Path', 'env:'). \
                        add_parameter('Name', env_key). \
                        add_parameter('Value', env_value). \
                        add_parameter('Force', True). \
                        add_cmdlet('Out-Null').add_statement()

            # so the client executes a powershell script and doesn't need to
            # deal with complex PS objects, we run the script in
            # Invoke-Expression and convert the output to a string
            # if a user wants to get the raw complex objects then they should
            # use RunspacePool and PowerShell directly
            powershell.add_cmdlet("Invoke-Expression").add_parameter("Command",
                                                                     script)
            powershell.add_cmdlet("Out-String").add_parameter("Stream")
            powershell.invoke()

        return "\n".join(powershell.output), powershell.streams, \
               powershell.had_errors
def execute_ps ( self , script , configuration_name = DEFAULT_CONFIGURATION_NAME , environment = None ) : log . info ( "Executing PowerShell script '%s'" % script ) with RunspacePool ( self . wsman , configuration_name = configuration_name ) as pool : powershell = PowerShell ( pool ) if environment : for env_key , env_value in environment . items ( ) : # Done like this for easier testing, preserves the param order log . debug ( "Setting env var '%s' on PS script execution" % env_key ) powershell . add_cmdlet ( 'New-Item' ) . add_parameter ( 'Path' , 'env:' ) . add_parameter ( 'Name' , env_key ) . add_parameter ( 'Value' , env_value ) . add_parameter ( 'Force' , True ) . add_cmdlet ( 'Out-Null' ) . add_statement ( ) # so the client executes a powershell script and doesn't need to # deal with complex PS objects, we run the script in # Invoke-Expression and convert the output to a string # if a user wants to get the raw complex objects then they should # use RunspacePool and PowerShell directly powershell . add_cmdlet ( "Invoke-Expression" ) . add_parameter ( "Command" , script ) powershell . add_cmdlet ( "Out-String" ) . add_parameter ( "Stream" ) powershell . invoke ( ) return "\n" . join ( powershell . output ) , powershell . streams , powershell . had_errors