-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConvertTo-DottedDecimalIPv4.ps1
56 lines (48 loc) · 1.55 KB
/
ConvertTo-DottedDecimalIPv4.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
function ConvertTo-DottedDecimalIPv4 {
<#
.SYNOPSIS
Returns a dotted decimal IP address.
.DESCRIPTION
ConvertTo-DecimalIPv4 takes 32 bit unsigned integer address into a dotted decimal IP address.
Function aliased to 'ConvertTo-DecimalIP'
.PARAMETER IPAddress
An IP Address to convert.
.PARAMETER IncludeInput
Switch that will display input parameters in the output
.EXAMPLE
ConvertTo-DottedDecimalIPv4 -IPAddress 16885952
Would return
192.168.1.1
.EXAMPLE
ConvertTo-DottedDecimalIPv4 -IPAddress 16885952 -IncludeInput
Would return
IPAddress DottedDecimalIP
--------- ---------------
16885952 192.168.1.1
#>
[CmdletBinding(ConfirmImpact='None')]
[alias('ConvertTo-DottedDecimalIP')] #FunctionAlias
param(
[Parameter(Mandatory,HelpMessage='Please enter an IPvr address', Position = 0, ValueFromPipeline)]
[ipaddress[]] $IPAddress,
[switch] $IncludeInput
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($curIPAddress in $IPAddress) {
if ($IncludeInput) {
New-Object -TypeName 'psobject' -Property ([ordered] @{
IPAddress = $curIPAddress.Address
DottedDecimalIP =$curIPAddress.IPAddressToString
})
} else {
Write-Output -InputObject $curIPAddress.IPAddressToString
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}