Private/Format.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# Copyright 2018-2020, Alexis La Goutte <alexis.lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

function Format-ArubaCPMacAddress {

    <#
        .SYNOPSIS
        Format Mac Address

        .DESCRIPTION
        Format Mac Address

        .EXAMPLE
        Format-ArubaCPMacAddress 00:01:02:03:04:05

        Format Mac Address (Remove Dash, Colon, dots Whitespace....)

    #>

    Param(
        [Parameter (Mandatory = $true)]
        [string]$mac
    )

    #From https://github.com/lazywinadmin/PowerShell/blob/master/TOOL-Clean-MacAddress/Clean-MacAddress.ps1
    $mac_clean = $mac
    $mac_clean = $mac_clean -replace "-", "" #Replace Dash
    $mac_clean = $mac_clean -replace ":", "" #Replace Colon
    $mac_clean = $mac_clean -replace "/s", "" #Remove whitespace
    $mac_clean = $mac_clean -replace " ", "" #Remove whitespace
    $mac_clean = $mac_clean -replace "\.", "" #Remove dots
    $mac_clean = $mac_clean.trim() #Remove space at the beginning
    $mac_clean = $mac_clean.trimend() #Remove space at the end

    $mac_clean
}