Share via


How to create a credentialcache object in powershell

Question

Friday, March 23, 2012 11:27 PM

Hi,

I want to use powershell to create CredentialCache and add credentil to it.

[System.Net.CredentialCache]$credentialCache = New-Object System.Net.CredentialCache
$credential = New-Object System.Net.NetworkCredential("username", "password")
$credentialCahe.Add("http://...", "Negotiate", $credential)

However, the first line $credentialCache is $null. What is missing?

Thanks.

All replies (5)

Monday, March 26, 2012 6:06 PM ✅Answered

Sorry for the typo in my post. But it was not the problem.

[System.Net.CredentialCache]$c = New-Object System.Net.CredentialCache

$c

Nothing print out.

It doesn't print anything but object is already created. To confirm the same run following commnd:

[System.Net.CredentialCache]$c = New-Object System.Net.CredentialCache
GM -InputObject $c

I guess you are trying to provide proxy details to send web request or to send mail. If that is the case you may find following links helpful.

http://blogs.msdn.com/b/buckh/archive/2004/07/28/199706.aspx

http://msdn.microsoft.com/en-us/library/59x2s2s6.aspx

Hope this helps...!!!

Thanks & Regards
Bhavik Solanki

Please click “Mark as Answer” if this post answers your question and click "Vote as Helpful if this Post helps you.


Saturday, March 24, 2012 1:13 AM

I think there is typo for $credentialCache variable :)

Check variable name in your last line of the script. I guess it shold as below.

[System.Net.CredentialCache]$credentialCache = New-Object System.Net.CredentialCache
$credential = New-Object System.Net.NetworkCredential("username", "password")
$credentialCache.Add("http://...", "Negotiate", $credential)

Thanks & Regards
Bhavik Solanki

Please click “Mark as Answer” if this post answers your question and click "Vote as Helpful if this Post helps you.


Monday, March 26, 2012 7:04 AM

Hi,

It seems like that you have typed a wrong word : $credentialCahe .

Is there any update about the issue?

In addition, I also would like suggest you refer to the below link for more information:

CredentialCache Class

http://msdn.microsoft.com/en-us/library/system.net.credentialcache.aspx

Hope this helps.

Best Regards,

Yan Li

Yan Li

TechNet Community Support


Monday, March 26, 2012 5:17 PM

Sorry for the typo in my post. But it was not the problem.

[System.Net.CredentialCache]$c = New-Object System.Net.CredentialCache

$c

Nothing print out.


Monday, March 26, 2012 10:54 PM

Thanks! Problem solved!