← 返回命令列表

Linux command

winrm 命令

网络

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Run a command

python -c "import winrm; s = winrm.Session('[host]', auth=('[user]', '[pass]')); print(s.run_cmd('ipconfig').std_out)"

Run PowerShell command

python -c "import winrm; s = winrm.Session('[host]', auth=('[user]', '[pass]')); print(s.run_ps('Get-Process').std_out)"

Connect using HTTPS

python -c "import winrm; s = winrm.Session('[host]', auth=('[user]', '[pass]'), transport='ssl'); print(s.run_cmd('hostname').std_out)"

Connect with NTLM authentication

python -c "import winrm; s = winrm.Session('[host]', auth=('[domain\\user]', '[pass]'), transport='ntlm'); print(s.run_cmd('whoami').std_out)"

说明

pywinrm is a Python library for Windows Remote Management (WinRM), enabling command execution on Windows machines from Linux or other systems. WinRM is Microsoft's implementation of WS-Management protocol, providing remote management capabilities similar to SSH. The library supports multiple authentication methods: Basic (requires HTTPS or unencrypted setup), NTLM (works with domain and local accounts), Kerberos (for domain environments), and CredSSP (allows credential delegation). Connection uses HTTP port 5985 or HTTPS port 5986. pywinrm is extensively used by automation tools like Ansible for Windows management. It can execute both cmd.exe commands (run_cmd) and PowerShell scripts (run_ps), returning output, errors, and exit codes. Windows hosts must have WinRM enabled (Enable-PSRemoting -Force) and configured to accept the chosen authentication method.

参数

host
Windows target hostname or IP address.
auth
Tuple of (username, password) for authentication.
transport
Authentication method: basic, ntlm, kerberos, ssl, or credssp.
run_cmd(_command_, _args_)
Execute a Windows command (cmd.exe).
run_ps(_script_)
Execute a PowerShell script.
std_out
Standard output from command execution.
std_err
Standard error from command execution.
status_code
Exit code of the executed command.

FAQ

What is the winrm command used for?

pywinrm is a Python library for Windows Remote Management (WinRM), enabling command execution on Windows machines from Linux or other systems. WinRM is Microsoft's implementation of WS-Management protocol, providing remote management capabilities similar to SSH. The library supports multiple authentication methods: Basic (requires HTTPS or unencrypted setup), NTLM (works with domain and local accounts), Kerberos (for domain environments), and CredSSP (allows credential delegation). Connection uses HTTP port 5985 or HTTPS port 5986. pywinrm is extensively used by automation tools like Ansible for Windows management. It can execute both cmd.exe commands (run_cmd) and PowerShell scripts (run_ps), returning output, errors, and exit codes. Windows hosts must have WinRM enabled (Enable-PSRemoting -Force) and configured to accept the chosen authentication method.

How do I run a basic winrm example?

Run `python -c "import winrm; s = winrm.Session('[host]', auth=('[user]', '[pass]')); print(s.run_cmd('ipconfig').std_out)"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does host do in winrm?

Windows target hostname or IP address.