2016-11-27 45 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:當然。享受編碼 –

相關問題