Python执行Exchange PowerShell命令
#pip install pypsrp from pypsrp.powershell import PowerShell, RunspacePool from pypsrp.wsman import WSMan host = 'ex01.test19.com' username='test19\\user01' password = "Ypassword" wsman = WSMan(server=host, username=username, password=password, port=80, path='PowerShell', ssl=False, auth='kerberos', cer_validation=False) with wsman, RunspacePool(wsman, configuration_name="Microsoft.Exchange") as pool: ps = PowerShell(pool) #MessageSubject为模糊查询 # ps.add_cmdlet("Get-ExchangeServer").add_cmdlet("Get-MessageTrackingLog").add_parameter("-eventid", "send").add_parameter("-sender", "liuyana@test19.com").add_parameter("-start", "2024/6/13").add_parameter("-end", "2024/7/25").add_parameter("-MessageSubject", "t") Recipients = ['tt6@test19.com','tt5@test19.com'] #根据多个收件人查询 ps.add_cmdlet("Get-ExchangeServer").add_cmdlet("Get-MessageTrackingLog").add_parameter("-eventid", "send").add_parameter("-sender", "liuyana@test19.com").add_parameter("-start", "2024/6/13 15:00").add_parameter("-MessageSubject", "t").add_parameter("-Recipients", Recipients) output = ps.invoke() if output is not None: for item in output: res = item.adapted_properties # print(res) print(res['Sender'],res['Recipients'],res['MessageSubject'],res['Timestamp'])