2012-05-31 63 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"; 

建议?