(connection)
return runspace_pools
Queries the server for disconnected runspace pools and creates a list
        of runspace pool objects associated with each disconnected runspace
        pool on the server. Each runspace pool object in the returned array is
        in the Disconnected state and can be connected to the server by calling
        the connect() method on the runspace pool.

        :param connection: The connection object used to query the remote
            server for a list of Runspace Pools. Currently only
            pypsrp.wsman.WSMan is supported.
        :return: List<RunspacePool> objects each in the Disconnected state
Queries the server for disconnected runspace pools and creates a list
        of runspace pool objects associated with each disconnected runspace
        pool on the server. Each runspace pool object in the returned array is
        in the Disconnected state and can be connected to the server by calling
        the connect() method on the runspace pool.
Queries the server for disconnected runspace pools and creates a list of runspace pool objects associated with each disconnected runspace pool on the server . Each runspace pool object in the returned array is in the Disconnected state and can be connected to the server by calling the connect () method on the runspace pool .
def get_runspace_pools(connection):
        """
        Queries the server for disconnected runspace pools and creates a list
        of runspace pool objects associated with each disconnected runspace
        pool on the server. Each runspace pool object in the returned array is
        in the Disconnected state and can be connected to the server by calling
        the connect() method on the runspace pool.

        :param connection: The connection object used to query the remote
            server for a list of Runspace Pools. Currently only
            pypsrp.wsman.WSMan is supported.
        :return: List<RunspacePool> objects each in the Disconnected state
        """
        log.info("Getting list of Runspace Pools on remote host")
        wsen = NAMESPACES['wsen']
        wsmn = NAMESPACES['wsman']

        enum_msg = ET.Element("{%s}Enumerate" % wsen)
        ET.SubElement(enum_msg, "{%s}OptimizeEnumeration" % wsmn)
        ET.SubElement(enum_msg, "{%s}MaxElements" % wsmn).text = "32000"

        # TODO: support wsman:EndOfSequence
        response = connection.enumerate("http://schemas.microsoft.com/wbem/"
                                        "wsman/1/windows/shell", enum_msg)
        shells = response.findall("wsen:EnumerateResponse/"
                                  "wsman:Items/"
                                  "rsp:Shell", NAMESPACES)

        runspace_pools = []
        for shell in shells:
            shell_id = shell.find("rsp:ShellId", NAMESPACES).text
            pool = RunspacePool(connection)
            pool.id = shell_id
            pool.shell.shell_id = shell_id
            pool.shell.opened = True
            pool._new_client = True

            # Seems like the server sends all pools not just disconnected but
            # the .NET API always sets the state to Disconnected when callling
            # GetRunspacePools so we replicate that here
            pool.state = RunspacePoolState.DISCONNECTED

            enum_msg = ET.Element("{%s}Enumerate" % wsen)
            ET.SubElement(enum_msg, "{%s}OptimizeEnumeration" % wsmn)
            ET.SubElement(enum_msg, "{%s}MaxElements" % wsmn).text = "32000"
            filter = ET.SubElement(enum_msg, "{%s}Filter" % wsmn,
                                   Dialect="http://schemas.dmtf.org/wbem/wsman"
                                           "/1/wsman/SelectorFilter")
            selector_set = SelectorSet()
            selector_set.add_option("ShellId", shell_id)
            filter.append(selector_set.pack())

            resp = connection.enumerate("http://schemas.microsoft.com/wbem/"
                                        "wsman/1/windows/shell/Command",
                                        enum_msg)
            commands = resp.findall("wsen:EnumerateResponse/wsman:Items/"
                                    "rsp:Command", NAMESPACES)
            pipelines = {}
            for command in commands:
                command_id = command.find("rsp:CommandId", NAMESPACES).text

                powershell = PowerShell(pool)
                powershell.id = command_id
                powershell._command_id = command_id
                powershell.state = PSInvocationState.DISCONNECTED
                pipelines[powershell.id] = powershell

            pool.pipelines = pipelines
            runspace_pools.append(pool)
        return runspace_pools
def get_runspace_pools ( connection ) : log . info ( "Getting list of Runspace Pools on remote host" ) wsen = NAMESPACES [ 'wsen' ] wsmn = NAMESPACES [ 'wsman' ] enum_msg = ET . Element ( "{%s}Enumerate" % wsen ) ET . SubElement ( enum_msg , "{%s}OptimizeEnumeration" % wsmn ) ET . SubElement ( enum_msg , "{%s}MaxElements" % wsmn ) . text = "32000" # TODO: support wsman:EndOfSequence response = connection . enumerate ( "http://schemas.microsoft.com/wbem/" "wsman/1/windows/shell" , enum_msg ) shells = response . findall ( "wsen:EnumerateResponse/" "wsman:Items/" "rsp:Shell" , NAMESPACES ) runspace_pools = [ ] for shell in shells : shell_id = shell . find ( "rsp:ShellId" , NAMESPACES ) . text pool = RunspacePool ( connection ) pool . id = shell_id pool . shell . shell_id = shell_id pool . shell . opened = True pool . _new_client = True # Seems like the server sends all pools not just disconnected but # the .NET API always sets the state to Disconnected when callling # GetRunspacePools so we replicate that here pool . state = RunspacePoolState . DISCONNECTED enum_msg = ET . Element ( "{%s}Enumerate" % wsen ) ET . SubElement ( enum_msg , "{%s}OptimizeEnumeration" % wsmn ) ET . SubElement ( enum_msg , "{%s}MaxElements" % wsmn ) . text = "32000" filter = ET . SubElement ( enum_msg , "{%s}Filter" % wsmn , Dialect = "http://schemas.dmtf.org/wbem/wsman" "/1/wsman/SelectorFilter" ) selector_set = SelectorSet ( ) selector_set . add_option ( "ShellId" , shell_id ) filter . append ( selector_set . pack ( ) ) resp = connection . enumerate ( "http://schemas.microsoft.com/wbem/" "wsman/1/windows/shell/Command" , enum_msg ) commands = resp . findall ( "wsen:EnumerateResponse/wsman:Items/" "rsp:Command" , NAMESPACES ) pipelines = { } for command in commands : command_id = command . find ( "rsp:CommandId" , NAMESPACES ) . text powershell = PowerShell ( pool ) powershell . id = command_id powershell . _command_id = command_id powershell . state = PSInvocationState . DISCONNECTED pipelines [ powershell . id ] = powershell pool . pipelines = pipelines runspace_pools . append ( pool ) return runspace_pools