在Python上执行PowerShell脚本

时间:2018-11-27 23:25:02

标签: python-3.x windows powershell

我正在尝试执行以下Windows PowerShell脚本(Get-Event-Logs.ps1):

Get-EventLog system -After (Get-Date).AddDays(-30) -Instance 44

它应该输出如下内容:

Index Time          EntryType   Source                 InstanceID Message
----- ----          ---------   ------                 ---------- -------
21056 Nov 27 15:47  Information Microsoft-Windows...           44 Windows Update started downloading an update.
21045 Nov 27 15:23  Information Microsoft-Windows...           44 Windows Update started downloading an update.
21044 Nov 27 15:23  Information Microsoft-Windows...           44 Windows Update started downloading an update.
21043 Nov 27 15:23  Information Microsoft-Windows...           44 Windows Update started downloading an update.
21042 Nov 27 15:23  Information Microsoft-Windows...           44 Windows Update started downloading an update.
21005 Nov 27 12:18  Information Microsoft-Windows...           44 Windows Update started downloading an update.
20940 Nov 26 18:42  Information Microsoft-Windows...           44 Windows Update started downloading an update.

我正在使用以下代码在python中执行:

import subprocess, sys
p = subprocess.Popen(['powershell.exe', 'Get-Event-Logs.ps1'], stdout=subprocess.PIPE,universal_newlines=True)
out, err = p.communicate()
print(out)

我所得到的只是一片空白。

我要去哪里错了?

0 个答案:

没有答案