Reputation: 573
I'm trying to get python remote powershell working using pywinrm from a docker container but hitting a wall connecting to the remote host i cant find a working example anywhere with ssl working (and not going to use it without) but below is what i've pieced together from the docs and my basic understanding of python, hopefully someone can see where i'm going wrong
Enter-PSSession -ComputerName x.x.x.x -UseSSL -Credential $creds;
Here are the details from the python3 attempt.
python3 --version
Python 3.4.2
pip --version
pip 9.0.1 from /usr/local/lib/python3.4/dist-packages (python 3.4)
pip show pywinrm
Name: pywinrm
Version: 0.2.2
Summary: Python library for Windows Remote Management
Home-page: http://github.com/diyan/pywinrm/
Author: Alexey Diyan
Author-email: [email protected]
License: MIT license
Location: /usr/local/lib/python3.4/dist-packages
Requires: six, xmltodict, requests, requests-ntlm
#!/usr/bin/env python3
import winrm
import base64
p = winrm.protocol.Protocol(
endpoint='https://<some_ip_here>:5986/wsman',
transport='ssl',
username='<some_username_here>',
password='<some_password_here>',
server_cert_validation='ignore')
shell_id = p.open_shell()
command_id = p.run_command(shell_id, 'ipconfig', ['/all'])
std_out, std_err, status_code = p.get_command_output(shell_id, command_id)
p.cleanup_command(shell_id, command_id)
p.close_shell(shell_id)
File "./open_winrm.py", line 13, in <module>
shell_id = p.open_shell()
File "/usr/local/lib/python3.4/dist-packages/winrm/protocol.py", line 132, in open_shell
res = self.send_message(xmltodict.unparse(req))
File "/usr/local/lib/python3.4/dist-packages/winrm/protocol.py", line 207, in send_message
return self.transport.send_message(message)
File "/usr/local/lib/python3.4/dist-packages/winrm/transport.py", line 190, in send_message
raise InvalidCredentialsError("the specified credentials were rejected by the server")
winrm.exceptions.InvalidCredentialsError: the specified credentials were rejected by the server
FROM node:7.7.3
ENV DEBCONF_NONINTERACTIVE_SEEN="true" \
DEBIAN_FRONTEND="noninteractive"
RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y autoremove && \
apt-get clean
RUN apt-get install -y etherwake locales locales-all python3 && \
curl https://bootstrap.pypa.io/get-pip.py | python3 && \
python3 -m pip install pywinrm
Upvotes: 1
Views: 872