My little part of the Internet

Generating Passwords using PowerShell

Even now – after all this time – passwords are hard.

Yes, I know we should all be using Cloud with its fancy KeyStore/Key Vaults or enterprise store such as CyberArk. We all know we should not be chosing them. However, like it or not ‘things’ still need passwords. Whether its for an encryption key, wireless network or just a plain and simple password.

Vendors are also part of the problem, placing restrictions on types of characters or even positioning of them within a password. Still. In 2020! (VMware and Cisco are pretty horrific at this)

Also when you are building stuff in automation, its inevitable you will need some sort of password generating. I use PowerShell a lot and found methods that could be used to do this.

Voila my new GitHub project

This is based on using the Psuedo Random Number Generator (PRNG) which is a feature provided by the Windows Cryptographic Service Provider (CSP) which generates randomness in a ‘good enough’ manner. If you need more than this then well you know why and what to do about it but for most uses this is pretty good.

It uses vendor safe methods and arrangments out of the box with a pretty good 16 character length. You can append flags to make it stronger, output a number of them or make them readable. Its up to you. Your choice.

# Import the module
PS > import-module .\Password-Functions.psm1

# Run the function
PS > New-Password

Want longer length ? Want more than one ?

PS > New-Password -Length 20 -count 3

Remember, the passwords being returned back as an object you can then store into other variables.

PS > $pass=New-Password

You can obviously use the PowerShell SecureString method to store and manipulate if need be. (Some decent tips at

PS > $pass=New-Password

PS > $secpass=(ConvertTo-SecureString $pass -AsPlainText -Force)
PS > $secpass

PS > $secpass | ConvertFrom-SecureString

PS > $secpass | ConvertFrom-SecureString | Out-File ".\MyPassword.txt"


  1. Ghumbar

    I agree about vendors. What is that all about in the century even ?
    Nice solution, man.

    • kevster

      Lets hope it will get better, I am sure they are listening ! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 Kevsters Blog

Theme by Anders NorénUp ↑