首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >向Windows凭据库中添加新条目

向Windows凭据库中添加新条目
EN

Stack Overflow用户
提问于 2020-10-10 17:00:28
回答 2查看 2.5K关注 0票数 0

我希望能够使用PowerShell向我的Windows凭据库添加多个条目。

我搜索了一下,发现了下面的代码:

代码语言:javascript
运行
复制
[Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
$vault = New-Object Windows.Security.Credentials.PasswordVault
$cred = New-Object windows.Security.Credentials.PasswordCredential
$cred.Resource = 'My Credentials'
$cred.UserName = 'MyDomain\MyUserName'
$cred.Password = 'MyPassword'
$vault.Add($cred)
Remove-Variable cred # So that we don't have the password lingering in memory!

问题是新条目存储在Web凭据库中,而不是存储在Windows凭据库中。我一定是漏掉了什么。我怎么才能修好它?

PS:我知道有更好的方法来存储密码,但这并不重要。我们把注意力集中在保险库上吧。:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-10-10 20:30:43

继续我的评论,看看这些工具:

代码语言:javascript
运行
复制
Find-Module -name '*credential*' | Format-Table -AutoSize
# Results
<#
Version        Name                          Repository Description
-------        ----                          ---------- -----------
2.0            CredentialManager             PSGallery  Provides access to credentials in the Windows Credential Manager
1.1.0          CredentialSpec                PSGallery  Tools to create and find Credential Spec files used to run Windows Server Containers with Active Directory ide...
1.1            VPNCredentialsHelper          PSGallery  A simple module to set the username and password for a VPN connection through PowerShell. Huge thanks to Jeff ...
1.0.4          WindowsCredential             PSGallery  Management module for Windows Credential Store.
3.6.30         CredentialRetriever           PSGallery  Retrieve Credentials from CyberArk Central Credential Provider Web Service, or Local Credential Provider using...
1.1.0          PSCredentialTools             PSGallery  PSCredentialTools provides various methods for securely storing and retrieving credentials used in PowerShell ...
1.0.0.0        SelectCredential              PSGallery  A module for selecting the credential stored in variables
1.1            CredentialsManager            PSGallery  The module Credentials Manager provides you with convenient and safe way to store your credentials to file sys...
1.0            NubusTech.CredentialStore     PSGallery  CredentialStore saves powershell credentials securely to file
1.3            MiCredentialModule            PSGallery  Saves/Retrieves credentials to/from a file (with encrypted password) so you can automate tasks that need diffe...
1.0.5          AxCredentialVault             PSGallery  Grants fast, secure access to credential objects in Azure
1.3            vaultcredential               PSGallery  Manages credentials in the credential vault
0.0.1          SecureCredentials             PSGallery  This module allow to secure store encrypted credentials for running powershell daemon
1.0.11         pscredentialmanager           PSGallery  This module allows management and automation of Windows cached credentials.
4.5            BetterCredentials             PSGallery  A (compatible) major upgrade for Get-Credential, including support for storing credentials in Windows Credenti...
2.1.0          PSJsonCredential              PSGallery  A set of commands for exporting and importing PSCredentials to a json file.
1.0.3          CredentialManagement          PSGallery  Manage Credentials stored in the Windows Credential Manager
1.0.0          CredentialLocker              PSGallery  CredentialLocker is a module that provides commandlets to manage credentials in the password vault....
3.0            CredentialUtility             PSGallery  This is a credential manager tool which comes with handy PowerShell cmdlets { Get-Password; Save-Password; Sho...
1.2.2.20190715 SimplyCredential              PSGallery  Simply Module for windows credentials.
1.1.7          CredentialStore               PSGallery  CredentialStore saves powershell credentials securely to file
1.1            PS.CredentialManager          PSGallery  A credential manager module for PowerShell. Securely stores and retrieves credentials using the Windows Data P...
1.1.1.0        IntelliTect.CredentialManager PSGallery  Provides an easy-to-use interface to the Windows Credential Manager via PowerShell.
2.0.4.0        StoredPSCredential            PSGallery  Stores serialized PSCredential objects in HKCU and retrieves them. Encryption can only be reversed by the same...
1.0.2          Get-AwsTemporaryCredential    PSGallery  Retrieves AWS Credentials from a stored profile and uses these to obtain temporary credentials for the specifi...
1.0.548        PSCredentialStore             PSGallery  A simple credential manager to store and reuse multiple credential objects.
1.0.0.0        BAMCIS.CredentialManager      PSGallery  Provides a PowerShell wrapper around the Windows Credential Manager Win32 APIs.
0.1.1          SCOrchDev-StoredCredential    PSGallery  A module retrieving PSCredential from credential manager. Forked from https://gist.github.com/toburger/2947424...
1.0.1          MrACredential                 PSGallery  A module to manage creating, saving, and importing credentials using encryption keys.
1.1.7          CredentialStore.AzureKeyVault PSGallery  Import and Export functionality to sync CredentialStore with Azure KeyVault
1.1            New-Credential                PSGallery  Simply creates an object (System.Management.Automation.PSCredential) that can be used with the parameter "-Cre...
1.0.7          TUN.Credentials               PSGallery  Provides easy to use methods to manage and use credentials. Documentation of module at https://github.com/echa...
2.1            SecuredCredential             PSGallery  SecuredCredential Routines for modules supported. This module is published in my new book 'Cloud Integration C...
#>

Install-Module -Name CredentialManager
Import-Module -name CredentialManager
(Get-Module -Name CredentialManager).ExportedCommands
# Results
<#
Key                     Value
---                     -----
Get-StoredCredential    Get-StoredCredential
Get-StrongPassword      Get-StrongPassword
New-StoredCredential    New-StoredCredential
Remove-StoredCredential Remove-StoredCredential
#>

# Get specifics for a module, cmdlet, or function
(Get-Command -Name New-StoredCredential ).Parameters
(Get-Command -Name New-StoredCredential ).Parameters.Keys
Get-help -Name New-StoredCredential  -Examples
Get-help -Name New-StoredCredential  -Full
Get-help -Name New-StoredCredential  -Online

# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Cmdlet |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{}
}|
Out-GridView -PassThru -Title '
Available cmdlets which has a specific parameter'

Get-Command -CommandType Function |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{}
}|
Out-GridView -PassThru -Title '
Available functions which has a specific parameter'

# Get property enums/options for a specifc cmdlet/function
(Get-Service | Select-Object -First 1).Status.GetType()
[System.ServiceProcess.ServiceControllerStatus]::
GetNames([System.ServiceProcess.ServiceControllerStatus])

另外,看看这个:机密管理开发发行版

什么是秘密管理?

秘密管理模块通过提供一组cmdlet来帮助用户管理机密,这些cmdlet允许您使用本地保险库提供程序在本地存储机密,并访问远程金库中的机密。该模块支持一种可扩展的模型,其中本地和远程金库可以在本地机器上注册和取消注册,供每个用户使用,用于访问和检索机密。该模块利用现有的秘密库,例如,它使用凭证管理器(Cred Man)在Windows上提供默认的本地金库体验。本模块的重点是从现有的金库中检索/使用秘密,将高级的秘密/金库管理留给现有的金库。虽然这个模块最终将是跨平台的,但该模块的alpha版本目前只在Windows平台上工作。想要更详细地解释秘密管理的目标,请关注Ignite 2019年的这个会议。

https://devblogs.microsoft.com/powershell/secrets-management-development-release

或者只是老派:

代码语言:javascript
运行
复制
cmdkey /?

Creates, displays, and deletes stored user names and passwords.

The syntax of this command is:

CMDKEY [{/add | /generic}:targetname {/smartcard | /user:username {/pass{:password}}} | /delete{:targetname | /ras} | /list{:targetname}]

Examples:

  To list available credentials:
     cmdkey /list
     cmdkey /list:targetname

  To create domain credentials:
     cmdkey /add:targetname /user:username /pass:password
     cmdkey /add:targetname /user:username /pass
     cmdkey /add:targetname /user:username
     cmdkey /add:targetname /smartcard

  To create generic credentials:
     The /add switch may be replaced by /generic to create generic credentials

  To delete existing credentials:
     cmdkey /delete:targetname

  To delete RAS credentials:
     cmdkey /delete /ras

cmdkey /list

Currently stored credentials:

    Target: MicrosoftAccount:target=SSO_POP_Device
    Type: Generic
    User: ...
    Saved for this logon only

    Target: WindowsLive:target=virtualapp/didlogical
    Type: Generic
    User: ...
    Local machine persistence

cmdkey /add:$env:COMPUTERNAME /user:postanote /pass:SomeSuperSecretPassword1

CMDKEY: Credential added successfully.
cmdkey /list

Currently stored credentials:

    Target: MicrosoftAccount:target=SSO_POP_Device
    Type: Generic
    User: ...
    Saved for this logon only

    Target: WindowsLive:target=virtualapp/didlogical
    Type: Generic
    User: ...
    Local machine persistence

    Target: Domain:target=104DB2FE-76B8-4
    Type: Domain Password
    User: postanote
票数 0
EN

Stack Overflow用户

发布于 2021-06-22 16:03:50

基于这些注释,您可能希望使用我在这里发布的解决方案,它是完全独立的代码片段,因此不需要模块:

Accessing Windows Credential Manager from PowerShell

(你需要一直滚动到底部)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64296032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档