Public/Get-Salt.ps1

using namespace System.Security.Cryptography

function Get-Salt {
    <#
        .SYNOPSIS
        Generates a cryptographically secure random byte array to be used as a salt.

        .DESCRIPTION
        Creates a secure random byte array of the specified length using the
        System.Security.Cryptography.RandomNumberGenerator class. Salts are typically
        used in cryptographic operations, such as password hashing, to ensure that
        each operation has a unique input.

        .PARAMETER Length
        Specifies the length of the salt to generate. The default is 32 bytes.

        .INPUTS
        None. You can't pipe objects to Get-Salt.

        .OUTPUTS
        byte[]. A cryptographically secure random byte array of the specified length.

        .EXAMPLE
        PS> Get-Salt -Length 64

        Generates a 64-byte salt and displays it as an array of bytes.

        .LINK
        https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator
    #>

    [OutputType([Byte[]])]
    [CmdletBinding()]
    param(
        [Parameter(Position = 0)]
        [int] $Length = 32
    )

    begin {
        $Salt = [byte[]]::new($Length)
    }
    process {
        [RandomNumberGenerator]::Fill($Salt)
        Write-Output $Salt
    }
    clean {
        $Salt.Clear()
    }
}