'Powershell remoting over SSH through python

I have a PowerShell command $ses = New-PSSession -HostName hostname -UserName username to establish the remote session with the target host after providing the password in the PowerShell prompt.

Now, I am using the subprocess package to automate the same in python. After running the command from python, How to Pass the password to the PowerShell prompt from python after running the below code?

import subprocess as sp

op = sp.run(['pwsh', '-Command', 'hostname'], stdout=sp.PIPE, stderr=sp.STDOUT)
print(op.stdout.decode())

Please help me with this.

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source