部分代码如下:
from winrm.protocol import Protocol
endpoint = f"http://{server}:5985/wsman"
params = {
‘username’: username,
‘password’: password,
‘transport’: ‘ntlm’
}
protocol = Protocol(endpoint, **params)
shell_id = protocol.open_shell()
command = “start powershell Copy-Item -Path ‘{source_dir}’ -Destination ‘{destination_dir}’ -Recurse -Force”
command_id = protocol.run_command(shell_id, command)
std_out, std_err, status_code = protocol.get_command_output(shell_id, command_id)
print(std_err, status_code)
protocol.cleanup_command(shell_id, command_id)
protocol.close_shell(shell_id)
注意:代码中的变量要换成实际的值