我有一个powershell命令来使用winrm运行它。
result = session.run_ps('get-wmiobject -namespace root\SecurityCenter2 -computername localhost -Query "Select * from AntiVirusProduct"')我想把这部分命令作为变量:
"Select * from AntiVirusProduct"比如:
query = "Select * from AntiVirusProduct"
result = session.run_ps('get-wmiobject -namespace root\SecurityCenter2 -computername localhost -Query query')我怎么才能在蟒蛇身上做到呢?
发布于 2022-07-26 11:23:27
在这里,一个简单的f-字符串应该能做到这一点:
query = "Select * from AntiVirusProduct"
result = session.run_ps(f'get-wmiobject -namespace root\\SecurityCenter2 -computername localhost -Query "{query}"')如果这对你有用,请告诉我,因为我手头没有一台windows机器可以在上面测试。
https://stackoverflow.com/questions/73122405
复制相似问题