-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find-MCASIPSubnet.ps1
48 lines (48 loc) · 1.36 KB
/
Find-MCASIPSubnet.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
<#
.Synopsis
Find-MCASIPSubnet
.DESCRIPTION
Find-MCASIPSubnett searches the specified IP Address in all registered MCAS IP ranges
.PARAMETER IPAddress
IP Address
.EXAMPLE
.\Find-MCASIPSubnet.ps1 -IPAddress 77.56.162.123
#>
[CmdletBinding()]
Param
(
# IP Address
[Parameter(Mandatory=$true)]
[ValidateScript({$_ -match [IPAddress]$_ })]
[string]
$IPAddress
)
Begin
{
If(!$CASCredential)
{
Write-Warning "You must first connect to MCAS"
Break
}
[System.Management.Automation.PSCredential]$Credential = $CASCredential
}
Process{
$IPSubnetData = [System.Collections.ArrayList]::new()
$CurrentIPRanges = Get-MCASSubnetCollection -Credential $Credential
ForEach($IPR in $CurrentIPRanges)
{
ForEach($subn in $IPR.subnets.originalString){
$object =[PSCustomObject]@{
IPRangeName = $IPR.name
Subnet = $subn}
[void]$IPSubnetData.Add($object)
}
}
$Result = $IPSubnetData | Where-Object {$_.subnet -like "*$IPAddress*"}
If([string]::IsNullOrEmpty($Result))
{ Write-Warning "No registered IP range found in MCAS with IP Address $IPAddress"}
Else{
$Result
}
}
End{}