Script Bits

My collection of random bits of PowerShell scripts I find very useful. These could be full PowerShell scripts, PowerShell functions, PowerShell modules, or smaller bits.

Get Chocolatey Package Version

Created 2019-07-21

This is a simple PowerShell function I created that simply gets the version of the Chocolatey package URL parameter.


function Get-ChocoPackageVersion {
    # Gets the version of the Chocolatey package specified by the URL using the -ChocoPackageVersion parameter.
    # Defaults to GoogleChrome if you do not specify the ChocoPackageURL parameter.
        [String]$ChocoPackageURL = ""
    $script:ChocoPackageVersion = ((Invoke-RestMethod -Uri $ChocoPackageURL).Split("`r`n") | Select-String "<title>").ToString() -split " " | Select-Object -Last 1

Get-ChocoPackageVersion -ChocoPackageURL ""
Write-Output "`nRetrieved package version: [$script:ChocoPackageVersion]"


Retrieved package version: [7.7.1]

Pronounceable Random Password


Creates a random password that is actually pronounceable, making it possible to remember, but more importantly in my case, much quicker to type.

I converted this handy Script Bit from a PHP equivalent a colleague of mine had created a number of years ago. There is a single “Length” switch that allows you to specify the number of syllables that are produced.

New-Passwd -Length 4 -Count 10


function New-Passwd {

A simple script that generates a random, but human-pronounceable password.

Version: 2.0
This script creates a random password based on human-pronounceable syllables.
You can adjust the number of syllables, and when working with it interactively,
includes the ability to generate multiple passwords. The generated password
will include a symbol character in a random location, and a 2-4 digit number suffix.

When integrating this function into a script, you'll likely want to use the -HideOutput
switch to prevent the password from being outputted to the console.


Default generates one password that is four (4) syllables long, 15-17 character length total.

Example output:
PS > Jabgot@darsay8472

New-Passwd -Length 20 -Count 5

Generates 5 passwords that are each 20-syllables long.

Example output:
PS > Neoreonuasantotlenlodjusveitavfihpotretvifruajigvuolua;tiuket6348
PS > Coasuukocfekbestajbacnutbabheptaksegcui.sesnadsotjuncaesojpou7255
PS > Paeruamohsadheimukbanneakui;pujgodmejsuinegjaobitfoffejgafheu2701
PS > Hapdaobagtiecokbihlubkiurubroelephep-munlijdumgemcuspagmuvkub4728
PS > Dejtegbia{gonbimpilpiltavvardiiribdujsevvujfovripdornopjiodoj3586

New-Passwd -HideOutput

Generates one default password that is four (4) syllables long, 15-17 character length total,
and does not show the output. It is useful to include this switch when calling from within
a script where you will be using the $script:Passwd variable elsewhere.
Default is to write output.

Example output:
PS > 

        #Default length in syllables.
        [Int]$Length = 4,
        #Default number of passwords to create.
        [Int]$Count = 1,
        #Hides the output. useful when used within a script.
    Begin {
        #consonants except hard to speak ones
        [Char[]]$lowercaseConsonants = "bcdfghjklmnprstv"
        [Char[]]$uppercaseConsonants = "BCDFGHJKLMNPRSTV"
        [Char[]]$lowercaseVowels = "aeiou"
        $lowercaseConsantsVowels = $lowercaseConsonants+$lowercaseVowels
        [Char[]]$numbers = "0123456789"
        #special characters
        [Char[]]$specialCharacters = '!$.;#@{+&}?:+_="%>-*/^'+"'"

        $countNum = 0
    Process {
        while ($countNum -le $Count-1) {
            $script:Passwd = ''
            #random location for special char between first syllable and length
            $specialCharSpot = Get-Random -Minimum 1 -Maximum $Length
            for ($i=0; $i -lt $Length; $i++) {
                if ($i -eq $specialCharSpot) {
                    #add a special char
                    $script:Passwd += ($specialCharacters | Get-Random -Count 1)
                #Start with uppercase
                if ($i -eq 0) {
                    $script:Passwd += ($uppercaseConsonants | Get-Random -Count 1)
                } else {
                    $script:Passwd += ($lowercaseConsonants | Get-Random -Count 1)
                $script:Passwd += ($lowercaseVowels | Get-Random -Count 1)
                $script:Passwd += ($lowercaseConsantsVowels | Get-Random -Count 1)
            #add a number at the end
            $randNumNum = Get-Random -Minimum 2 -Maximum 5
            $script:Passwd += (($numbers | Get-Random -Count $randNumNum)-join '')
            if ($HideOutput) {
                # The $Passwd is not shown as output.
            } else {
                Write-Output "$script:Passwd"



Leave a Reply

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