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
Outputstream; - isolated
Error,Warning,Verbose,Debug,InformationandProgressstreams; - a persistent
RunspacePoolthat keeps apowershell.exeprocess alive across many pipelines; - a builder-style
PipelineAPI.
§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 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
SecureStringtransport. - error
- Error type for the
psrp-rscrate. - 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-Commandmetadata 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
RunspacePoolacross multiple callers. - transport
- Thin wrapper around
winrm_rs::Shellthat ferries PSRP fragments.
Structs§
- Winrm
Client - Async WinRM (WS-Management) HTTP client.
- Winrm
Config - Configuration for a
WinrmClientconnection. - Winrm
Credentials - Credentials for WinRM authentication.
Enums§
- Auth
Method - Authentication method for the WinRM HTTP transport.
- Winrm
Error - Errors that can occur during WinRM operations.