-
Notifications
You must be signed in to change notification settings - Fork 721
/
Clean-MacAddress.ps1
107 lines (85 loc) · 2.86 KB
/
Clean-MacAddress.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function Clean-MacAddress {
<#
.SYNOPSIS
Function to cleanup a MACAddress string
.DESCRIPTION
Function to cleanup a MACAddress string
.PARAMETER MacAddress
Specifies the MacAddress
.PARAMETER Separator
Specifies the separator every two characters
.PARAMETER Uppercase
Specifies the output must be Uppercase
.PARAMETER Lowercase
Specifies the output must be LowerCase
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:33:44:55'
001122334455
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Uppercase
001122DDEEFF
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase
001122ddeeff
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator '-'
00-11-22-dd-ee-ff
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator '.'
00.11.22.dd.ee.ff
.EXAMPLE
Clean-MacAddress -MacAddress '00:11:22:dD:ee:FF' -Lowercase -Separator :
00:11:22:dd:ee:ff
.OUTPUTS
System.String
.NOTES
Francois-Xavier Cat
lazywinadmin.com
@lazywinadmin
.Link
https://github.com/lazywinadmin/PowerShell
#>
[OutputType([String], ParameterSetName = "Upper")]
[OutputType([String], ParameterSetName = "Lower")]
[CmdletBinding(DefaultParameterSetName = 'Upper')]
param
(
[Parameter(ParameterSetName = 'Lower')]
[Parameter(ParameterSetName = 'Upper')]
[String]$MacAddress,
[Parameter(ParameterSetName = 'Lower')]
[Parameter(ParameterSetName = 'Upper')]
[ValidateSet(':', 'None', '.', "-")]
$Separator,
[Parameter(ParameterSetName = 'Upper')]
[Switch]$Uppercase,
[Parameter(ParameterSetName = 'Lower')]
[Switch]$Lowercase
)
BEGIN {
# Initial Cleanup
$MacAddress = $MacAddress -replace "-", "" #Replace Dash
$MacAddress = $MacAddress -replace ":", "" #Replace Colon
$MacAddress = $MacAddress -replace "/s", "" #Remove whitespace
$MacAddress = $MacAddress -replace " ", "" #Remove whitespace
$MacAddress = $MacAddress -replace "\.", "" #Remove dots
$MacAddress = $MacAddress.trim() #Remove space at the beginning
$MacAddress = $MacAddress.trimend() #Remove space at the end
}
PROCESS {
IF ($PSBoundParameters['Uppercase']) {
$MacAddress = $macaddress.toupper()
}
IF ($PSBoundParameters['Lowercase']) {
$MacAddress = $macaddress.tolower()
}
IF ($PSBoundParameters['Separator']) {
IF ($Separator -ne "None") {
$MacAddress = $MacAddress -replace '(..(?!$))', "`$1$Separator"
}
}
}
END {
Write-Output $MacAddress
}
}