Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
In the Windows environment, managing and retrieving stored credentials is a critical task for system administrators. Stored credentials are often used to automate tasks, access network resources, and manage user authentication securely. PowerShell, a powerful scripting language and command-line shell, provides cmdlets to handle credentials efficiently. One such cmdlet is Get-StoredCredential
.
However, it is important to note that Get-StoredCredential
is not a native cmdlet in PowerShell. Instead, it is part of the Credential Manager module, which can be installed from the PowerShell Gallery. This article will guide you through the process of installing the Credential Manager module and using Get-StoredCredential
to retrieve stored credentials in Windows.
Examples:
Installing the Credential Manager Module:
To use Get-StoredCredential
, you first need to install the Credential Manager module from the PowerShell Gallery. Open PowerShell with administrative privileges and run the following command:
Install-Module -Name CredentialManager -Force -Scope CurrentUser
This command installs the Credential Manager module for the current user.
Retrieving Stored Credentials:
After installing the module, you can use the Get-StoredCredential
cmdlet to retrieve stored credentials. Here is an example:
Import-Module CredentialManager
$credential = Get-StoredCredential -Target "MyNetworkResource"
In this example, replace "MyNetworkResource"
with the target name of the stored credential you want to retrieve. The $credential
variable will hold the retrieved credential object.
Using Retrieved Credentials: Once you have the credential object, you can use it in scripts to authenticate against resources. For example, to map a network drive using the retrieved credentials:
$username = $credential.UserName
$password = $credential.GetNetworkCredential().Password
New-PSDrive -Name "Z" -PSProvider FileSystem -Root "\\NetworkShare" -Credential (New-Object System.Management.Automation.PSCredential($username, (ConvertTo-SecureString $password -AsPlainText -Force)))
This script maps a network drive to \\NetworkShare
using the stored credentials.
Storing New Credentials:
You can also store new credentials using the New-StoredCredential
cmdlet from the Credential Manager module:
New-StoredCredential -Target "MyNewResource" -UserName "username" -Password "password" -Persist LocalMachine
Replace "MyNewResource"
, "username"
, and "password"
with the appropriate values. The -Persist
parameter specifies where the credential is stored.