Python : Interactions avec Windows
Le module Pywinrm
https://pypi.org/project/pywinrm/0.2.2/
Le module Pywinrm est un module pour Python permettant d'interagir avec Windows par l'intermédiaire du protocole WinRM.
= Préparation sur la machine Windows
En admettant que la machine Windows ait déjà WinRM (sinon, voir Ansible et Windows, il peut être nécessaire d'utiliser la commande suivante dans le CMD de la machine :
winrm set winrm/config/service @{AllowUnencrypted="true"}
Utilisation sur Python
<syntaxhighlight lang="python"> s = winrm.Session('windows-host.example.com', auth=('john.smith', 'secret')) r = s.run_cmd('ipconfig', ['/all']) >>> r.status_code 0 >>> r.std_out Windows IP Configuration
Host Name . . . . . . . . . . . . : WINDOWS-HOST Primary Dns Suffix . . . . . . . : Node Type . . . . . . . . . . . . : Hybrid IP Routing Enabled. . . . . . . . : No WINS Proxy Enabled. . . . . . . . : No
... >>> r.std_err </syntaxhighlight>