0

I have a ASP.NET C# web app with a Login control authenticating via AD. Is it possible to use the Login control's credentials on a Powershell cmd where I need to specify creds without being asked for the password?

Sam
  • 265
  • 1
  • 3
  • 9

1 Answers1

0

I've found a solution, but I don't know how secure it is.

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";

Suggestions?

Sam
  • 265
  • 1
  • 3
  • 9