我从一个不断返回空对象的网页中调用以下代码。我从类似的过程(Get-ADOrganizationalUnit -LDAPFilter '(name=*)‘-SearchBase 'OU=Staff、OU=All User、DC=xx、DC=xx、DC=xx')运行其他powershell cmdlet,它工作良好,并给出了组织单元的列表,因此我知道页面可以执行powershell ok,但由于某些原因,我在获取proxyaddresses列表时遇到了问题。完全卡住了,因为我不知道如何取回这些地址。
任何帮助都将不胜感激。
谢谢达伦
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发布于 2016-11-28 03:38:43
要做到这一点,有很多方法。我给出了以下方法来满足你的要求。希望这能满足你的需要。
# 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@yourdomain.com
Get-ADObject -Properties mail, proxyAddresses -Filter {mail -eq "email@yourdomain.com" -or proxyAddresses -eq "smtp:email@yourdomain.com"}
# 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 "(|(mail=email@yourdomain.com)(proxyAddresses=smtp:email@yourdomain.com))"
# LDAP with wildcards
Get-ADObject -LDAPFilter "(|(mail=*emailportion*)(proxyAddresses=*emailportion*))"
# Using SIP
Get-ADObject -Properties proxyAddresses -Filter {proxyAddresses -eq "sip:email@yourdomain.com"}https://stackoverflow.com/questions/40835288
复制相似问题