Accessing Windows Credential Manager from PowerShell

前端 未结 5 1922
忘了有多久
忘了有多久 2020-12-04 22:38

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

相关标签:
5条回答
  • 2020-12-04 23:03

    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

    0 讨论(0)
  • 2020-12-04 23:12

    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/

    0 讨论(0)
  • 2020-12-04 23:14

    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

    0 讨论(0)
  • 2020-12-04 23:20

    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

    0 讨论(0)
  • 2020-12-04 23:26

    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

    0 讨论(0)
提交回复
热议问题