# Credential: how to best use them ?

## Information

This article was written for a presentation of the French Powershell UserGroup.

This presentation can be seen on Youtube on the FRPSUG channel

# Module : BetterCredentials

During my last research, I came across, by chance, the module BetterCredentials from Jaykul

Please note that the module is not completely dry :-)

As he says himself so well ;-)

The goal of BetterCredentials is to provide a Get-Credential command fully compatible with previous versions that improves the original Get-Credential by adding additional functionality that is not present in the integrated command. Specifically, storing credentials for automation, and providing more complete prompts with an explanation of the use of credentials

In summary it is a Get-Credential but better …

For use, just install the module directly from the PSGallery

Install-Module -Name BetterCredentials -scope CurrentUser -AllowClobber -force

The -AllowClobber is important for the installation

Then, classically, import the module

Import-Module BetterCredentials

the list of available commands is as follows

PS > Get-Command -Module BetterCredentials

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Find-Credential                                    4.5        BetterCredentials
Function        Get-Credential                                     4.5        BetterCredentials
Function        Remove-Credential                                  4.5        BetterCredentials
Function        Set-Credential                                     4.5        BetterCredentials
Function        Test-Credential                                    4.5        BetterCredentials

The first command that interests us of course is Get-Credential.

As with any new command, let's start by looking at the help

Get-Help -Name BetterCredentials\Get-Credential -Detailed

Notice that I prefixed the command with the name of the module so that the system understands that I want the help of Get-Credential of the module and not that of the default command.

Reading the help one sentence interested me a lot

It also supports storing and retrieving credentials in your Windows Credential Manager, but otherwise functions identically to the built-in command

interesting !

Rather than storing the information (UserName and Password) in a file like I mentioned on the post Credential : How To use them ? this module is capable of storing them in the Windows Vault.

Let's see this function a little more precisely.

--------                                      --------

So far nothing surprising since the result is a Credential object with Username and Password.

ok, ok but before we talked about storage in the Windows Vault.

Let's take a look in the Credential Manager and actually we find an entry corresponding to our user with his password.

In order to be able to recover this account just take the command

$cred = Get-Credential -UserName MyUsername -Domain MyDomain If the user exists in the vault it recovers this account otherwise it makes a prompt to ask for the password In our case the user is in the vault PS >$cred = Get-Credential -UserName MyUsername -Domain MyDomain
PS > $cred Target : MicrosoftPowerShell:user=MyDomain\MyUsername TargetAlias : Type : Generic Persistence : Enterprise Description : LastWriteTime : 2/10/2019 7:25:35 PM UserName : MyDomain\MyUsername Password : System.Security.SecureString This$cred variable can be used for example in the following command

Enter-PSSession -ComputerName MyComputer -Credential \$cred

I admit that I don't really know what to think of this module.

The idea seems interesting to me but this module still needs to be developed which does not seem to be the case. Another blocking point, since it is based on the Credential Manager of Windows, this module is naturally not Cross-Platform :-(

But it is there, the strength of the community therefore notice to all fans who would like to participate in the evolution of this module :-)