Apache Airflow provider package for Windows Remote Management (WinRM) protocol integration enabling remote command execution on Windows systems
npx @tessl/cli install tessl/pypi-apache-airflow-providers-microsoft-winrm@3.11.0Apache Airflow provider package for Windows Remote Management (WinRM) protocol integration. Enables Airflow workflows to execute commands and scripts on remote Windows systems through secure WinRM connections, supporting multiple authentication methods and comprehensive remote Windows administration capabilities.
pip install apache-airflow-providers-microsoft-winrmfrom airflow.providers.microsoft.winrm.hooks.winrm import WinRMHook
from airflow.providers.microsoft.winrm.operators.winrm import WinRMOperatorVersion compatibility utilities:
from airflow.providers.microsoft.winrm.version_compat import BaseHook, BaseOperator, get_base_airflow_version_tupleType imports for development:
from collections.abc import Sequence
from winrm.protocol import Protocol
from airflow.utils.context import Contextfrom airflow.providers.microsoft.winrm.hooks.winrm import WinRMHook
# Create hook with connection ID
hook = WinRMHook(ssh_conn_id='winrm_default')
# Or create hook with direct parameters
hook = WinRMHook(
remote_host='192.168.1.100',
username='admin',
password='password',
transport='ntlm',
remote_port=5985
)
# Execute command
return_code, stdout, stderr = hook.run('dir C:\\')
# Execute PowerShell script
return_code, stdout, stderr = hook.run(
'Get-Process | Where-Object CPU -gt 100',
ps_path='powershell'
)from airflow import DAG
from airflow.providers.microsoft.winrm.operators.winrm import WinRMOperator
from datetime import datetime
dag = DAG(
'winrm_example',
start_date=datetime(2024, 1, 1),
schedule_interval='@daily'
)
# Execute Windows command
win_cmd = WinRMOperator(
task_id='check_windows_services',
command='sc query',
ssh_conn_id='winrm_default',
dag=dag
)
# Execute PowerShell script
ps_script = WinRMOperator(
task_id='get_system_info',
command='Get-ComputerInfo | Select-Object WindowsProductName, TotalPhysicalMemory',
ps_path='powershell',
ssh_conn_id='winrm_default',
dag=dag
)The provider follows Airflow's hook-operator pattern:
Comprehensive WinRM connection management with support for multiple authentication methods, secure transports, and extensive configuration options for enterprise Windows environments.
class WinRMHook(BaseHook):
def __init__(
self,
ssh_conn_id: str | None = None,
endpoint: str | None = None,
remote_host: str | None = None,
remote_port: int = 5985,
transport: str = "plaintext",
username: str | None = None,
password: str | None = None,
service: str = "HTTP",
keytab: str | None = None,
ca_trust_path: str | None = None,
cert_pem: str | None = None,
cert_key_pem: str | None = None,
server_cert_validation: str = "validate",
kerberos_delegation: bool = False,
read_timeout_sec: int = 30,
operation_timeout_sec: int = 20,
kerberos_hostname_override: str | None = None,
message_encryption: str | None = "auto",
credssp_disable_tlsv1_2: bool = False,
send_cbt: bool = True,
) -> None: ...
def get_conn(self) -> Protocol: ...
def run(
self,
command: str,
ps_path: str | None = None,
output_encoding: str = "utf-8",
return_output: bool = True,
) -> tuple[int, list[bytes], list[bytes]]: ...
def test_connection(self) -> tuple[bool, str]: ...Airflow operator for seamless integration of Windows remote commands into data pipeline workflows, with templating support and comprehensive error handling.
class WinRMOperator(BaseOperator):
template_fields: Sequence[str] = ("command",)
template_fields_renderers = {"command": "powershell"}
def __init__(
self,
*,
winrm_hook: WinRMHook | None = None,
ssh_conn_id: str | None = None,
remote_host: str | None = None,
command: str | None = None,
ps_path: str | None = None,
output_encoding: str = "utf-8",
timeout: int = 10,
expected_return_code: int | list[int] | range = 0,
**kwargs,
) -> None: ...
def execute(self, context: Context) -> list | str: ...Cross-version compatibility utilities ensuring seamless operation across different Airflow versions while maintaining consistent API access to base classes.
def get_base_airflow_version_tuple() -> tuple[int, int, int]: ...
AIRFLOW_V_3_0_PLUS: bool
AIRFLOW_V_3_1_PLUS: bool
BaseOperator: type
BaseHook: typeThe provider raises AirflowException for:
WinRM operation timeouts are handled gracefully with automatic retries for long-running processes.