I\'m using PowerShell 2.0 (necessary because of SP2010) On Windows Server 2008 R2. I need to retrieve credentials for a process from the Windows Credential Manager. I can\'t
I found a really good post, this code will print all usernames, resources and passwords
[Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
$vault = New-Object Windows.Security.Credentials.PasswordVault
$vault.RetrieveAll() | % { $_.RetrievePassword();$_ }
Credits to Todd's post
Microsoft has a SecretsManagement module in development: https://devblogs.microsoft.com/powershell/secrets-management-development-release/ https://devblogs.microsoft.com/powershell/secrets-management-module-vault-extensions/
According to the docs, the PasswordVault class isn't supported on Windows Server 2008 R2.
Minimum supported server Windows Server 2012
https://msdn.microsoft.com/library/windows/apps/windows.security.credentials.passwordvault.aspx
You'll need to access the Win32 API to interact with the Credential Manager.
CredMan.ps1 from the Technet scripting gallery nicely demonstrates this.
For simpler usage patterns, like just listing principals or adding new credentials, you can also use cmdkey, a built-in Windows Command-line utility for credential management
For reusing stored Credentials in PowerShell, this guy seems to have found a way to build a PSCredential
from a Generic Credential handle from the Credential Store, using a technique similar to that of CredMan.ps1: Get-StoredCredential
In powershell5 type:
Install-Module CredentialManager -force
Then
New-StoredCredential -Target $url -Username $ENV:Username -Pass ....
and later
Get-StoredCredential -Target ....
Source code for the module is https://github.com/davotronic5000/PowerShell_Credential_Manager