Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Powershell以连接到exchange服务器并从队列中删除邮件_Python_Powershell_Exchange Server_Exchange Server 2010 - Fatal编程技术网

Python Powershell以连接到exchange服务器并从队列中删除邮件

Python Powershell以连接到exchange服务器并从队列中删除邮件,python,powershell,exchange-server,exchange-server-2010,Python,Powershell,Exchange Server,Exchange Server 2010,我有一段Python代码,应该使用Powershell连接到exchange服务器并从队列中删除消息。(我是Powershell的新手) 我发现这也导致了。基本上说我应该做: Remove-Message -Server SERVERNAME -Filter {FromAddress -like '*MATCH*'} -WithNDR $false 其中,SERVERNAME和MATCH将由代码给出。。。我的问题是我应该如何在Powershell中运行它?所以我这样做了: powershell

我有一段Python代码,应该使用Powershell连接到exchange服务器并从队列中删除消息。(我是Powershell的新手)

我发现这也导致了。基本上说我应该做:

Remove-Message -Server SERVERNAME -Filter {FromAddress -like '*MATCH*'} -WithNDR $false
其中,
SERVERNAME
MATCH
将由代码给出。。。我的问题是我应该如何在Powershell中运行它?所以我这样做了:

powershell -NoExit -Command "COMMAND"
其中
COMMAND
是上面的命令。我想用子流程运行它。当我手动测试命令时,会出现以下错误:

The term 'Remove-Message' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:15
+ Remove-Message <<<< -Server SERVERNAME -Filter {FromAddress -like '*MATCH*'} -WithNDR $false
    + CategoryInfo : ObjectNotFound: (Remove-Message:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
术语“删除消息”不能识别为cmdlet、函数、脚本文件或可操作程序的名称。检查
名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。
第1行字符:15

+删除消息我没有尝试使用删除消息cmdlet。假设您提供的命令可以按预期工作。你应该做以下的事情

1) 编写脚本以包含命令,包括连接到exchange和删除消息

    if ((gcm Remove-Message -ErrorAction Ignore) -eq $null)
    {
      $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://$($env:COMPUTERNAME).$($env:USERDNSDOMAIN)/Powershell?serializationLevel=Full;ExchClientVer=14.2.247.5" -Authentication kerberos
      Import-Module (Import-PSSession $session) -global
    }
    Remove-Message -Server SERVERNAME -Filter {FromAddress -like '*MATCH*'} -WithNDR $false
请对
-ConnectionUri
进行适当更改,因为我刚刚演示了如何使用完全限定的域名连接到本地

2) 使用以下代码调用此脚本时,不要使用
-NoExit
,除非您不想在删除完成后继续使用该powershell控制台

powershell -command ". 'PS_FILE_PATH'"
3) 如果需要将参数传递到脚本中,可以将它们组合到
-命令“'script.ps1'arg1 arg2”
。并在脚本中与
$args[0]
一起使用它们,或者先用
param($match,$servername)
声明param,然后在脚本中使用

我对Python不太熟悉,因此无法提供有关如何使用Python调用的更多信息