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
謝謝Ranadip。我會給這些一些去。 –
@DarrenM:當然。享受編碼 –