I have a powershell command to run it with winrm.
result = session.run_ps('get-wmiobject -namespace root\SecurityCenter2 -computername localhost -Query "Select * from AntiVirusProduct"')
I want to give this part of command as a variable :
"Select * from AntiVirusProduct"
like :
query = "Select * from AntiVirusProduct"
result = session.run_ps('get-wmiobject -namespace root\SecurityCenter2 -computername localhost -Query query')
How can i do it in python?
>Solution :
A simple f-string should do the trick here:
query = "Select * from AntiVirusProduct"
result = session.run_ps(f'get-wmiobject -namespace root\\SecurityCenter2 -computername localhost -Query "{query}"')
Let me know if that works for you as I don’t have a windows machine handy to test it on.