繁体   English   中英

Windows 8上的Powershell Exchange 2010

[英]Powershell Exchange 2010 on Windows 8

在Win 7下,Follow脚本运行正常,没有任何问题,但是当我在Windows 8上加载我的应用程序以查看全部损坏时,我发现该脚本将无法正常工作。 这是一个非常简单的脚本,用于加载用户交换邮箱以搜索用户在较大应用程序中是否具有邮箱。 它实际上是用python编写的,因为我使用IronPython作为插件系统。

    password = SecureString()
    str_password = "PASSWORD"
    str_user = "EXCHUSER"
    uri = "http://" + exchangeServerIP + "/PowerShell"

    for c in str_password:
        password.AppendChar(c)

    creds = PSCredential(str_user, password)

    connectionInfo = WSManConnectionInfo(Uri(uri), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", creds)

    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic

    runspace = RunspaceFactory.CreateRunspace(connectionInfo)

    runspace.Open()

    powershell = PowerShell.Create()
    powershell.AddCommand("Get-Mailbox")
    if self.txtUsername.Text != "*":
        powershell.AddParameter("Identity", self.txtUsername.Text)

    powershell.AddParameter("ResultSize", "Unlimited")
    powershell.Runspace = runspace

    results = powershell.Invoke()

    if results == None or results.Count <= 0:
        MessageBox.Show("No mailboxes can be found!")
        runspace.Close()
        runspace.Dispose()
        powershell.Dispose()
        return

    self.dataGridView1.Rows.Clear()

    for result in results:
    >>>>>>> if result.Properties != None:   (ERROR HERE)  <<<<<<<
                if result.Properties["Name"] != None:
                    if result.Properties["Name"].Value != None:
                        System.Console.WriteLine(result.Properties["Name"].Value.ToString())

    runspace.Dispose()
    runspace.Close()
    runspace = None

    powershell.Dispose()
    powershell = None

    connectionInfo = None

我已经标记了在哪里我说出了result.Properties是NoneType的错误,在调试时我可以看到它已填充并且有正确的结果。 不知道Windows 8 / .net 4.5是否是问题的原因,但在win 7准确代码下没有null值时工作正常。 任何建议都会有很大帮助。

更新(答案):

经过不断的挖掘,我终于发现问题出在Powershell 3上。通过IronPython使用Powershell 2访问成员,我可以使用result.Members [“ Name”]。Value,但是使用Powershell 3和DLR,IronPython将在返回null值。 result.Members集合,所以我必须将其称为result.Name。 (结果= PSObject时)

让我知道您在上述代码的编译过程中遇到什么错误。

1.首先检查您的代码SDK版本是否与您当前的软件版本匹配。

2.使用Visual Studio 2008/09/10/11开发的代码/应用程序无法在Visual Studio 2012中使用。

3.如果您复制Windows 7应用程序文件以在win8中进行编译,它将无法正常工作。只需从vs 2012中的第一个开始创建/编码即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM