从PowerShell访问Windows凭据管理器

从PowerShell访问Windows凭据管理器

问题描述:

我正在Windows Server 2008 R2上使用PowerShell 2.0(由于SP2010而必须使用).我需要从Windows凭据管理器中检索过程的凭据.我似乎无法使其正常工作.

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 seem to make it work.

我收到了这段代码:

[Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
(new-object Windows.Security.Credentials.PasswordVault).RetrieveAll() | % { $_.RetrievePassword(); $_ }

两行代码都会引发错误

Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime : Unable to find type [Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]: make sure that the assembly containing this type is loaded.

(new-object Windows.Security.Credentials.PasswordVault).RetrieveAll() | % {$_.RetrievePassword(); $_ } 

分别.我一直在尝试以某种方式导入PasswordVault类.到目前为止,Google让我失败了,我什至无法找出它驻留在哪个程序集中.我想念什么?

respectively. I've been trying to somehow import the PasswordVault class. So far Google has failed me, I haven't even been able to find out which assembly it resides in. What am I missing?

在powershell5中输入:

In powershell5 type:

   Install-Module CredentialManager -force

然后

   New-StoredCredential -Target $url -Username $ENV:Username -Pass ....

及以后

   Get-StoredCredential -Target .... 

该模块的源代码为 https://github.com/davotronic5000/PowerShell_Credential_Manager