2016-11-27 38 views
1

我从保持返回空对象的网页调用以下代码。我运行其他PowerShell cmdlet从一个类似的过程(Get-ADOrganizationalUnit -LDAPFilter'(name = *)'-SearchBase'OU = Staff,OU =所有用户,DC = xx,DC = xx,DC = xx')并给了我一个组织单元列表,所以我知道该页面可以执行powershell,但出于某种原因,我在获取代理地址列表时遇到问题。完全卡住,因为我不知道如何检索代理地址。无法使用ASP.NET中的Get-ADUser获取代理地址

任何帮助将不胜感激。

感谢 达伦

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 

回答

0

有很多方法来实现这一目标。我已采取以下方法来满足您的要求。希望这能满足你的需求。

# sample Examples as CSV 

Get-ADUser MyUser01 -properties * | select-object name, samaccountname, surname, enabled, @{"name"="proxyaddresses";"expression"={$_.proxyaddresses}} | Export-Csv ProxyAddress.csv 

Get-ADUser -Filter * -SearchBase 'ou=TestOU,dc=domain,dc=com' -Properties proxyaddresses | select name, @{L='ProxyAddress_1'; E={$_.proxyaddresses[0]}}, @{L='ProxyAddress_2';E={$_.ProxyAddresses[1]}} | Export-Csv ProxyAddress.csv –NoTypeInformation 

# Will find any active directory object that has an exact match to the e-mail address you place in the filter ie. [email protected] 

Get-ADObject -Properties mail, proxyAddresses -Filter {mail -eq "[email protected]" -or proxyAddresses -eq "smtp:[email protected]"} 

# This filter (Using wildcards) will also grab not only smtp addresses but other types such as x500: eum: sip: etc. 

Get-ADObject -Properties mail, proxyAddresses -Filter {mail -like "*emailportion*" -or proxyAddresses -like "*emailportion*"} 

# Using a LDAP query to find the matching object 
Get-ADObject -LDAPFilter "(|([email protected])(proxyAddresses=smtp:[email protected]))" 

# LDAP with wildcards 

Get-ADObject -LDAPFilter "(|(mail=*emailportion*)(proxyAddresses=*emailportion*))" 

# Using SIP 

Get-ADObject -Properties proxyAddresses -Filter {proxyAddresses -eq "sip:[email protected]"} 
+0

谢谢Ranadip。我会给这些一些去。 –

+0

@DarrenM:当然。享受编码 –

相关问题