functions/Start-BitWardenServe.ps1

function Start-BitWardenServe {
<#
.SYNOPSIS
Start-BitWardenServe

.Description
Start a bw serve instance.

.Parameter [String]$Hostname
The hostname to listen the local bw service. Default: 127.0.0.1

.Parameter [Int64]$Port
The port to listen the local bw service. Default: 8087

.EXAMPLE
Start-BitWardenServe

.NOTES
Name: Start-BitWardenServe
Author: Felix Scholz
Version: 0.0.1.0
DateCreated: 2024-01-29

.LINK
- https://bitwarden.com/de-DE/help/cli/#serve

.COMPONENT
Requires PSEdition Core
Requires Version 7.0 or above
#>

    [CmdletBinding()]
    param(
        [Parameter()]
        [String]$Hostname="127.0.0.1",
        [Parameter()]
        [Int64]$Port=8087
    )
    BEGIN {}
    PROCESS {
        $Args = @('serve', '--hostname', "$Hostname", "--port", "$Port")

        Write-Verbose -Message "Command: bw $Args"
        $process = Start-Process -FilePath "$PSScriptRoot\..\private\bin\bw.exe" -Args $Args -PassThru `
            -NoNewWindow -Wait
        Write-Verbose -Message "Open with Id: $( $process.Id ); Handle: $( $process.Handles )"
}
    END {}
}