scripts/Publish-MyModule.ps1

function Publish-MyModule
{
    [CmdletBinding()]
    param (
        [Parameter()]
        [string]
        $Path
    )

    #localdev pre ps7: [Environment]::SetEnvironmentVariable('NuGetApiKey', '[your-nuget-api-key]', 'User')
    #localdev ps7: Set-Item -Path Env:NuGetApiKey -Value '[your-nuget-api-key]'

    if ($Path -eq '')
    {
        $Path = ('{0}\..\' -f $PSScriptRoot )
    }

    $confirmation = Read-Host ("Do you want to publish '{0}' to PowerShell Gallery?" -f $Path)
    if ($confirmation -eq 'y')
    {
        try
        {
            # Build a splat containing the required details and make sure to stop for errors which will trigger the catch
            $params = @{
                Path        = ('{0}\..\' -f $PSScriptRoot )
                NuGetApiKey = $env:NuGetApiKey
                ErrorAction = 'Stop'
            }
            
            Publish-Module @params
            Write-Output -InputObject ('PowerShell Module BcAdmin published to PowerShell Gallery')
        }

        catch
        {
            throw $_
        }
    }
}