0

I'd like to add credentials to the registry, but don't know where. Then I would like to use these credentials in a PowerShell script for new-psdrive. The user is a domain user, but the computer is not. Where to add credentials in the registry? How to assign credentials from a registry key to a variable?

  • Your question is interesting, but too broad. Please read about [how to ask a good question](http://stackoverflow.com/help/how-to-ask). – mklement0 Nov 29 '20 at 15:07
  • [This answer](https://stackoverflow.com/a/40029496/45375) shows you how to persist credentials in a _file_, which you could adapt to your needs (note: use on Windows only). – mklement0 Nov 29 '20 at 15:08

1 Answers1

1

You can use Credential Manager. With this module you can store credentials on your workstation and retrieve it for your scripts. Here is an example how to use it. This are the four commands this module provides:

Get-Command -Module CredentialManager


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-StoredCredential                               2.0        CredentialManager
Cmdlet          Get-StrongPassword                                 2.0        CredentialManager
Cmdlet          New-StoredCredential                               2.0        CredentialManager
Cmdlet          Remove-StoredCredential                            2.0        CredentialManager

Some further well written blog post.

To note, this module does not work for PowerShell Core.

Alex_P
  • 2,580
  • 3
  • 22
  • 37