Skip to main content

Crate psrp_rs

Crate psrp_rs 

Source
Expand description

Async MS-PSRP client for Rust, built on top of winrm-rs.

psrp-rs implements the PowerShell Remoting Protocol on top of WS-Management. It reuses winrm-rs for transport, authentication and SOAP envelope handling, and layers the PSRP fragment/CLIXML protocol on top to deliver:

  • typed PowerShell objects on the Output stream;
  • isolated Error, Warning, Verbose, Debug, Information and Progress streams;
  • a persistent RunspacePool that keeps a powershell.exe process alive across many pipelines;
  • a builder-style Pipeline API.

§Example

use psrp_rs::{RunspacePool, WinrmPsrpTransport};
use winrm_rs::{AuthMethod, WinrmClient, WinrmConfig, WinrmCredentials};

let client = WinrmClient::new(
    WinrmConfig {
        auth_method: AuthMethod::Ntlm,
        ..Default::default()
    },
    WinrmCredentials::new("administrator", "Passw0rd!", ""),
)?;

let (rpid, creation) = RunspacePool::<WinrmPsrpTransport>::build_creation_fragments(1, 1)?;
let transport = WinrmPsrpTransport::open(&client, "win-host.lab", &creation).await?;
let mut pool = RunspacePool::open_from_transport(transport, rpid, 1, 1).await?;

let objects = pool
    .run_script("Get-Process | Select-Object -First 5 Name, Id")
    .await?;
for obj in objects {
    println!("{obj:?}");
}

pool.close().await?;

§Scope

P0 covers: fragment/CLIXML primitives, opening a pool, running a script, collecting every standard stream. P1 extends to per-stream processing via the Pipeline builder (already available here) and a blocking wrapper in the blocking module. P2 items — <Ref>-based CLIXML round-tripping, pipeline input streaming, reconnect/disconnect — are still on the roadmap.

Re-exports§

pub use clixml::PsObject;
pub use clixml::PsValue;
pub use clixml::RefIdAllocator;
pub use clixml::parse_clixml;
pub use clixml::to_clixml;
pub use crypto::ClientSessionKey;
pub use crypto::SessionKey;
pub use error::PsrpError;
pub use error::Result;
pub use host::BufferedHost;
pub use host::HostCallKind;
pub use host::HostMethodId;
pub use host::NoInteractionHost;
pub use host::PsHost;
pub use metadata::CommandMetadata;
pub use metadata::CommandType;
pub use metadata::ParameterMetadata;
pub use pipeline::Argument;
pub use pipeline::Command;
pub use pipeline::Pipeline;
pub use pipeline::PipelineHandle;
pub use pipeline::PipelineResult;
pub use pipeline::PipelineState;
pub use records::ErrorCategoryInfo;
pub use records::ErrorRecord;
pub use records::ExceptionInfo;
pub use records::FromPsObject;
pub use records::InformationRecord;
pub use records::InvocationInfo;
pub use records::ProgressRecord;
pub use records::TraceRecord;
pub use records::WarningRecord;
pub use runspace::DisconnectedPool;
pub use runspace::PROTOCOL_VERSION;
pub use runspace::RunspacePool;
pub use runspace::RunspacePoolState;
pub use runspace::RunspacePoolStateMachine;
pub use shared::SharedRunspacePool;
pub use transport::PsrpTransport;
pub use transport::WinrmPsrpTransport;

Modules§

blocking
Synchronous wrapper around the async API.
clixml
CLIXML (MS-PSRP §2.2.5) — types and (de)serialization.
crypto
Session-key cryptography for MS-PSRP SecureString transport.
error
Error type for the psrp-rs crate.
fragment
PSRP fragment layer (MS-PSRP §2.2.4).
host
PowerShell host interface — handles server → client callbacks.
message
PSRP message layer (MS-PSRP §2.2.1, §2.2.2).
metadata
Get-Command metadata pipeline — a special kind of PSRP pipeline that asks the server which commands are available.
pipeline
Pipeline builder and executor.
records
Typed accessors for PowerShell record types.
runspace
Runspace pool: lifecycle state machine + async driver.
shared
Thread-safe sharing of a RunspacePool across multiple callers.
transport
Thin wrapper around winrm_rs::Shell that ferries PSRP fragments.

Structs§

WinrmClient
Async WinRM (WS-Management) HTTP client.
WinrmConfig
Configuration for a WinrmClient connection.
WinrmCredentials
Credentials for WinRM authentication.

Enums§

AuthMethod
Authentication method for the WinRM HTTP transport.
WinrmError
Errors that can occur during WinRM operations.