Private/Get-SpecComPort.ps1

Function Get-SpecComPort {
    [cmdletbinding()]
    param (
        [string]$inputString
    )

    # Define a regular expression pattern to match "(COMx)" at the end of the string
    #$pattern = '\(COM\d+\)$'
    $pattern = '\((COM\d+)\)$'

    # Use the -match operator to check if the string matches the pattern
    if ($inputString -match $pattern) {
        # Extract the matched portion using the automatic variable "$matches"
        $matchedText = $matches[1]
        return $matchedText
    } else {
        return 501
    }
}