我想使用 python 脚本运行以下 power-shell 命令:
timedetail = subprocess.check_output('powershell.exe Get-WinEvent -LogName Microsoft-Windows-TerminalServices-LocalSessionManager/Operational | Where { ($_.ID -eq "25" -or $_.ID -eq "21") -and ($_.TimeCreated -gt [datetime]::Today.AddDays(-2))} |Select TimeCreated , Message | sort-Object -Property TimeCreated -Unique | Format-List', startupinfo=st_inf,shell=False,stderr=subprocess.PIPE, stdin=subprocess.PIPE).decode('ANSI').strip().splitlines()
但这不适用于 python 代码,这显示错误:
[WinError 2] The system cannot find the file specified
任何人都可以帮助如何使用 python 代码运行 powershell 命令?
提前致谢。