无法使用ASP.NET中的Get-ADUser获取proxyaddress

时间:2016-11-27 23:50:18

标签: asp.net powershell

我有以下代码,我从一个不断返回空对象的网页调用。我从类似的程序运行其他PowerShell cmdlet(Get-ADOrganizationalUnit -LDAPFilter'(name = *)' -SearchBase' OU = Staff,OU = All Users,DC = xx,DC = xx ,DC = xx')工作正常,并给我一个组织单位的列表,所以我知道该页面可以执行powershell确定,但由于某种原因,我在获取代理地址列表时遇到问题。我完全陷入困境,因为我不知道如何检索代理地址。

非常感谢任何帮助。

感谢 达伦

   Public Function GetProxyAddresses(sUsername As String, sIPAddress As String) As StringBuilder
        Try
            Dim psConfig As RunspaceConfiguration = RunspaceConfiguration.Create
            Dim psRunSpace = RunspaceFactory.CreateRunspace(psConfig)
            psRunSpace.Open()

            Using psPipeline As Pipeline = psRunSpace.CreatePipeline

                psPipeline.Commands.AddScript("Get-ADUser " + sUsername + " -properties proxyaddresses | select-object @{""name""=""proxyaddresses"";""expression""={$_.proxyaddresses}}")

                Try
                    Dim builder = New StringBuilder
                    Dim results = psPipeline.Invoke()

                    For Each PSObject In results
                        builder.Append(PSObject.Properties("proxyAddresses").Value + "\n")
                    Next

                    GetProxyAddresses = builder

                End Try
            End Using
            psRunSpace.Close()

        Catch ex As System.Management.Automation.Remoting.PSRemotingTransportException
            AddLogEntry(ex.Message, "N/A", ex.ErrorCode, Now.Date, sUsername, sIPAddress, HttpContext.Current.Request.Url.AbsolutePath, System.Reflection.MethodInfo.GetCurrentMethod.Name)
        End Try
    End Function

1 个答案:

答案 0 :(得分:0)

有很多方法可以实现这一目标。我已经提供了以下方法来满足您的要求。希望这能满足您的需求。

 passwordTextField.borderStyle = UITextBorderStyle.none