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?
Asked
Active
Viewed 707 times
0
-
This might help: http://stackoverflow.com/questions/7109958/saving-credentials-for-reuse-by-powershell-and-error-convertto-securestring-ke – Christopher Rathermel May 31 '12 at 16:17
-
Can you elaborate on what you mean by:: "_where I need to specify creds without being asked for the password_" – Angshuman Agarwal May 31 '12 at 16:52
1 Answers
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