2012-05-31 62 views
0

我有一個ASP.NET C#web應用程序,通過AD進行登錄控制認證。是否有可能在Powershell cmd上使用Login控件的憑據,我需要指定信用而不需要輸入密碼?LoginView並將憑據傳遞給Powershell

+0

這可能有所幫助:http://stackoverflow.com/questions/7109958/saving-credentials-for-reuse-by-powershell-and-error-convertto-securestring-ke –

+0

你能詳細說明你的意思嗎: :「_我需要指定信用而不需要輸入密碼_」 –

回答

0

我找到了一個解決方案,但我不知道它有多安全。

string un = System.Web.HttpContext.Current.Session["UserName"].ToString(); 

string pw = System.Web.HttpContext.Current.Session["Password"].ToString(); 

sText += "$securePasssword = ConvertTo-SecureString \"" + pw + "\" -AsPlainText -Force \n"; 

sText += "$credentials = New-Object System.Management.Automation.PSCredential ($un, $securePasssword) \n"; 

sText += "$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $url -Authentication Kerberos -Credential $credentials \n"; 

sText += "Import-PSSession $Session \n"; 

建議?