Need a function to validate MAC Address input and if they were valid convert them to a format

Hope this function come in handy for someone out there

Any improvements advice are welcome.

Demo

RAW:

PowerShell
Edit|Remove
function Validate-MAC ($MACAddress) 
{ 
    $patterns = @( 
        '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$' 
        '^([0-9A-Fa-f]{4}.){2}([0-9A-Fa-f]{4})$' 
        '^([0-9A-Fa-f]{12})$') 
    if ($MACAddress -match ($patterns -join '|')) 
    { 
        $MACAddress = $MACAddress.ToUpper() 
        if (!($MACAddress -match "^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$")) 
        { 
            # XX-XX-XX-XX-XX-XX 
            if ($MACAddress -match "^([0-9A-Fa-f]{2}[-]){5}([0-9A-Fa-f]{2})$") 
            { 
                $MACAddress = $MACAddress -replace ('-'':') 
                return $MACAddress 
            } 
            # XXXX.XXXX.XXXX 
            if ($MACAddress -match "^([0-9A-Fa-f]{4}.){2}([0-9A-Fa-f]{4})$") 
            { 
                $MACAddress = $MACAddress -replace ('\.''') 
                $MACAddress = $MACAddress -replace '..(?!$)''$&:' 
                return $MACAddress 
            } 
            # XXXXXXXXXXXX 
            if ($MACAddress -match "([0-9A-Fa-f]{2}){5}([0-9A-Fa-f]{2})$") 
            { 
                $MACAddress = $MACAddress.Insert(2,':').Insert(5, ':').Insert(8, ':').Insert(11, ':').Insert(14, ':') 
                return $MACAddress 
            } 
        } 
        else 
        { 
            return $MACAddress 
        } 
    } 
    else 
    { 
        $false 
        Write-Host "MACAddress not in correct format: XX:XX:XX:XX:XX:XX'" -ForegroundColor Red 
    } 
} 
 
break 
 
Validate-MAC -MACAddress '01:23:45:67:89:ab' 
Validate-MAC -MACAddress '3D:F2:C9:A6:B3:00' 
 
Validate-MAC -MACAddress '001e.1324.683f' 
Validate-MAC -MACAddress '001E.1324.683F' 
 
Validate-MAC -MACAddress '00-25-86-DC-FD-3B' 
Validate-MAC -MACAddress '00-25-86-dc-fd-3b' 
 
Validate-MAC -MACAddress '002586DCFD3B' 
Validate-MAC -MACAddress '002586dcfd3b' 
 
Validate-MAC -MACAddress '00258D3B' 
Validate-MAC -MACAddress '002586fd3b'