Random String generation PowerShell Script that leaves out $ sign

This PS Script leaves out $ from Random String generation and tested in init.ps1, seems to work fine on up.ps1.

#Get-RandomString.psm1

# This function takes only multiples of 4 as length

Function Get-RandomString([int]$Length)

{

$ErrorActionPreference = "Stop";

$IndividualLength=$Length/4

$TokenSet = @{

        U = [Char[]]'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

        L = [Char[]]'abcdefghijklmnopqrstuvwxyz'

        N = [Char[]]'0123456789'

        S = [Char[]]'!"#%&''()*+,-./:;<=>?@[\]^_`{|}~'

    }

$Upper = Get-Random -Count $IndividualLength -InputObject $TokenSet.U

$Lower = Get-Random -Count $IndividualLength -InputObject $TokenSet.L

$Number = Get-Random -Count $IndividualLength -InputObject $TokenSet.N

$Special = Get-Random -Count $IndividualLength -InputObject $TokenSet.S

$StringSet = $Upper + $Lower + $Number + $Special

(Get-Random -Count $Length -InputObject $StringSet) -join ''

}


Call in init.ps1:

- Import the above module

- Invoke the function



Generated keys:


Error and fix:

OS: Windows 11 Professional

Docker Version: 4.15.0 (93002)

Scenario: Tried up.ps1 after initialisation of .env file and I started getting the following error. I had already switched to Windows Containers so, that wasn't the issue. Alternatively, restarted Docker Desktop, restarted machine and nothing worked. Finally, uninstalled Docker Desktop and reinstalled Docker for windows, version 4.16.0 and up.ps1 worked for me.

Error:

Error response from daemon: open \\.\pipe\docker_engine_windows: The system cannot find the file specified.

Building containers...

time="2023-01-14T02:46:27+11:00" level=warning msg="The \"SITECORE_XmCloud_dot_OrganizationId\" variable is not set. Defaulting to a blank string."

time="2023-01-14T02:46:27+11:00" level=warning msg="The \"RENDERING_HOST_INTERNAL_URI\" variable is not set. Defaulting to a blank string."

time="2023-01-14T02:46:27+11:00" level=warning msg="The \"SITECORE_XmCloud_dot_TenantId\" variable is not set. Defaulting to a blank string."

time="2023-01-14T02:46:27+11:00" level=warning msg="The \"JSS_EdgeWebsite_DEPLOYMENT_SECRET\" variable is not set. Defaulting to a blank string."

time="2023-01-14T02:46:27+11:00" level=warning msg="`scale` is deprecated. Use the `deploy.replicas` element"

time="2023-01-14T02:46:27+11:00" level=warning msg="`scale` is deprecated. Use the `deploy.replicas` element"

[+] Building 0.0s (0/0)

no valid drivers found: Error response from daemon: open \\.\pipe\docker_engine_windows: The system cannot find the file specified.

Reference: https://www.delftstack.com/howto/powershell/powershell-generate-random-strings/#generate-random-strings-with-get-random

Comments