How To Handle Passwords in PowerShell Automation

Spread the love

I have been writing automations using PowerShell for many years now. One common issue I notice with people’s code is the improper handling of passwords. In this blog, I share how to set up a Credential Manager on a SQLServer and use the same for handling passwords in automation.

To setup Credential Manager, we need to download and execute the following steps using scripts from my Github repo SQLMonitor.

1. Create tables


This SQL script creates 2 required tables – dbo.credential_manager & dbo.dbo.credential_manager_audit.

2. Create procedures

The above 4 procedures are used to add, remove, update & fetch credentials with Credential Manager.

3. Adjust appropriate permissions

This script creates a certificate-based login/user and signs all the procedures created above. Then execute permission is provided on the above procedures so anyone having access to the Credential Manager server can utilize the Credential Manager through the procedures.

Below are some sample ways to use the above procedures-

I would recommend watching the below video which explains Credential Manager to a great deal.

I hope this will help anyone writing automation for SQLServer using PowerShell or needs a Password Vault.

One Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.