1

I'm writing a c# program, it will use current user's credential to run a script.

How can I convert CredentialCache.DefaultCredentials object using in access web service to PSCredential object?

Or other better way to create PSCredential without storing username/password?

3
  • Are you trying to invoke Powershell via a webservice through the credentials of the user accessing the service?? Commented Jul 24, 2012 at 12:51
  • No, it is just two functions. Web service can use current user credential, and I want powershell does it too. Commented Jul 24, 2012 at 23:49
  • This can't be done. See [this question][1] [1]: stackoverflow.com/questions/3917779/… Commented May 1, 2013 at 11:31

1 Answer 1

0

No guarantees here, but you can at least try something like the following pseudocode

// DefaultCredentials returns an ICredentials reference // which can then be used to call GetCredentials, // and *that* returns a NetworkCredential. NetworkCredential netCredential = CredentialCache.DefaultCredentials.GetCredentials(..); // Now, with a NetworkCredential that *might* have a SecurePassword, you // could see if that would work to create a PSCredential. I haven't tested this, // and honestly I'm a bit dubious of the prospects, but its at least a thought. // There may be some translation necessary to even make that SecurePassword work, // assuming it is even available in your context, to something the PSCredential // can use. PSCredential psCredential = new PSCredential(netCredential.UserName, netCredential.SecurePassword); 

As noted, this is untested pseudocode, but hopefully it gives you a push in the right direction. Good luck.

Sign up to request clarification or add additional context in comments.

1 Comment

DefaultCredentials contains empty username and password.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.