diff --git a/functions/public/Assign-Tag.ps1 b/functions/public/Assign-Tag.ps1 new file mode 100644 index 0000000..7b609ab --- /dev/null +++ b/functions/public/Assign-Tag.ps1 @@ -0,0 +1,33 @@ +function Assign-Tag { + [CmdletBinding()] + param ( + [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Address] + $AddressObject, + [parameter(Mandatory=$true,Position=1)] + [ValidateNotNullOrEmpty()] + [PS.IPAM.Tag] + $Tag + ) + process { + $_params = @{ + Controller = [PS.IPAM.controllers]::addresses + Method = "PATCH" + } + $_id = $AddressObject.id + $_tagid = $Tag.id + + $_identifiers = @($_id) + + $_params.Add("Identifiers",$_identifiers) + + $_body = @{ } + $_body.Add("tag", $_tagid) + + $_params.Add("Params",$_body) + + Invoke-Request @_params + } +} +Export-ModuleMember -Function Assign-Tag \ No newline at end of file diff --git a/functions/public/Get-Address.ps1 b/functions/public/Get-Address.ps1 index 57c32cf..ecaf22e 100644 --- a/functions/public/Get-Address.ps1 +++ b/functions/public/Get-Address.ps1 @@ -36,10 +36,10 @@ function Get-Address { Type = [PS.IPAM.types]::address } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($id) } - "ByIP" { $_identifiers = ("search",$IP) } - "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses) } + "ByID" { $_identifiers = @($id); break } + "ByIP" { $_identifiers = ("search",$IP); break } + "ByHostName" { $_identifiers = ("search_hostname",$HostName); break } + "ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) @@ -47,6 +47,7 @@ function Get-Address { $_params.Item("Controller") = [PS.IPAM.controllers]::subnets $_identifiers = ($SubnetId,[PS.IPAM.controllers]::addresses) } + break } "BySubnetCIDR" { $_params.Item("Controller") = [PS.IPAM.controllers]::subnets @@ -54,6 +55,7 @@ function Get-Address { if (!$_subnetId) { throw "Cannot find subnet!" } $_identifiers = ($_subnetId,[PS.IPAM.controllers]::addresses) + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Nameserver.ps1 b/functions/public/Get-Nameserver.ps1 index 6e798fa..06fe325 100644 --- a/functions/public/Get-Nameserver.ps1 +++ b/functions/public/Get-Nameserver.ps1 @@ -11,12 +11,12 @@ function Get-Nameserver { $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) $_params = @{ - Controller = "tools" - SubController = "nameservers" + Controller = [PS.IPAM.controllers]::tools + SubController = [PS.IPAM.subcontrollers]::nameservers Method = "GET" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_nameserverId = $Id } + "ByID" { $_nameserverId = $Id; break } } $_identifiers = @($_nameserverId) $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Permissions.ps1 b/functions/public/Get-Permissions.ps1 index d86b94c..2cdc0a4 100644 --- a/functions/public/Get-Permissions.ps1 +++ b/functions/public/Get-Permissions.ps1 @@ -41,10 +41,10 @@ function Get-Permissions { Method = "GET" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($id) } - "ByIP" { $_identifiers = ("search",$IP) } - "ByHostName" { $_identifiers = ("search_hostname",$HostName) } - "ByTag" { $_identifiers = ("tags",$TagId,"addresses") } + "ByID" { $_identifiers = @($id); break } + "ByIP" { $_identifiers = ("search",$IP); break } + "ByHostName" { $_identifiers = ("search_hostname",$HostName); break } + "ByTag" { $_identifiers = ("tags",$TagId,"addresses"); break } "BySubnetId" { if ($IP) { $_identifiers = ($IP,$SubnetId) @@ -52,6 +52,7 @@ function Get-Permissions { $_params.Item("Controller") = "subnets" $_identifiers = ($SubnetId,"addresses") } + break } "BySubnetCIDR" { $_params.Item("Controller") = "subnets" @@ -59,6 +60,7 @@ function Get-Permissions { if (!$_subnetId) { throw "Cannot find subnet!" } $_identifiers = ($_subnetId,"addresses") + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Section.ps1 b/functions/public/Get-Section.ps1 index f866064..16ae03c 100644 --- a/functions/public/Get-Section.ps1 +++ b/functions/public/Get-Section.ps1 @@ -18,8 +18,8 @@ function Get-Section { Type = [PS.IPAM.types]::Section } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id) } - "ByName" { $_identifiers = @($Name) } + "ByID" { $_identifiers = @($Id); break } + "ByName" { $_identifiers = @($Name); break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Subnet.ps1 b/functions/public/Get-Subnet.ps1 index 71cbdb8..814f3af 100644 --- a/functions/public/Get-Subnet.ps1 +++ b/functions/public/Get-Subnet.ps1 @@ -54,7 +54,7 @@ function Get-Subnet { } switch ($PSCmdlet.ParameterSetName) { "ByCIDR" { - $_identifiers = @("cidr",$CIDR) + $_identifiers = @("cidr",$CIDR); break } "ByID" { $_identifiers = @($Id) @@ -66,25 +66,29 @@ function Get-Subnet { $_identifiers += "slaves" } } + break } "BySectionId" { $_params.Item("Controller") = "sections" $_sectionId = $SectionId - $_identifiers = @($_sectionId,"subnets") + $_identifiers = @($_sectionId,"subnets") + break } "BySectionName" { $_params.Item("Controller") = "sections" $_sectionId = (Get-Section -Name $SectionName).id if (!$_sectionId) { throw "Cannot find section!" } - $_identifiers = @($_sectionId,"subnets") + $_identifiers = @($_sectionId,"subnets") + break } "ByVrfId" { $_params.Item("Controller") = "vrf" $_vrfId = $VrfId $_identifiers = @($_vrfId,"subnets") + break } "ByVlanId" { $_params.Item("Controller") = "vlan" @@ -95,6 +99,7 @@ function Get-Subnet { $_identifiers = @($_vlanId,"subnets") if ($_sectionId) { $_identifiers += $_sectionId } + break } "ByVlanNumber" { $_params.Item("Controller") = "vlan" @@ -111,6 +116,7 @@ function Get-Subnet { $_identifiers = @($_vlanId,"subnets") if ($_sectionId) { $_identifiers += $_sectionId } + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-SubnetUsage.ps1 b/functions/public/Get-SubnetUsage.ps1 index 4cf1cbf..731de87 100644 --- a/functions/public/Get-SubnetUsage.ps1 +++ b/functions/public/Get-SubnetUsage.ps1 @@ -21,8 +21,9 @@ function Get-SubnetUsage { "ByCIDR" { $_subnetId = (Get-Subnet -CIDR $CIDR).id if (!$_subnetId) { throw "Cannot find subnet!" } + break } - "ByID" { $_subnetId = $Id } + "ByID" { $_subnetId = $Id; break } } $_identifiers = @($_subnetId,"usage") $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Get-Tag.ps1 b/functions/public/Get-Tag.ps1 index 606131c..31fa28f 100644 --- a/functions/public/Get-Tag.ps1 +++ b/functions/public/Get-Tag.ps1 @@ -38,6 +38,7 @@ function Get-Tag { } else { return $null } + break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/New-Subnet.ps1 b/functions/public/New-Subnet.ps1 index 72db734..3987f74 100644 --- a/functions/public/New-Subnet.ps1 +++ b/functions/public/New-Subnet.ps1 @@ -11,146 +11,68 @@ function New-Subnet { [ValidateNotNullOrEmpty()] [string] $CIDR, - [parameter( - Mandatory=$true, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Section identifier", - Position=1)] - [ValidateScript({ $_ -match "^\d+$" })] + [parameter(Mandatory=$true,HelpMessage="Section identifier",Position=1)] + [ValidateNotNullOrEmpty()] + [int] + $SectionId, + [parameter(Mandatory=$false,HelpMessage="Subnet description",Position=2)] [ValidateNotNullOrEmpty()] [string] - $SectionId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Subnet description", - Position=2)] - [string] $Description, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assigns subnet to VLAN", - Position=3)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VLAN",Position=3)] + [ValidateNotNullOrEmpty()] + [int] $VlanId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assigns subnet to VRF", - Position=4)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VRF",Position=4)] + [ValidateNotNullOrEmpty()] + [int] $VrfId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Master subnet id for nested subnet", - Position=5)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Master subnet id for nested subnet",Position=5)] + [ValidateNotNullOrEmpty()] + [int] $MasterSubnetId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Id of nameserver to attach to subnet", - Position=6)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Id of nameserver to attach to subnet",Position=6)] + [ValidateNotNullOrEmpty()] + [int] $NameserverId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu", - Position=7)] + [parameter(Mandatory=$false,HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",Position=7)] [switch] $ShowName, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if PTR records should be created for subnet", - Position=8)] + [parameter(Mandatory=$false,HelpMessage="Controls if PTR records should be created for subnet",Position=8)] [switch] $DNSRecursive, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls weather hostname DNS records are displayed", - Position=9)] + [parameter(Mandatory=$false,HelpMessage="Controls weather hostname DNS records are displayed",Position=9)] [switch] $DNSRecords, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if IP requests are allowed for subnet", - Position=10)] + [parameter(Mandatory=$false,HelpMessage="Controls if IP requests are allowed for subnet",Position=10)] [switch] $AllowRequests, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls which scanagent to use for subnet (default id 1)", - Position=11)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Controls which scanagent to use for subnet (default id 1)",Position=11)] + [ValidateNotNullOrEmpty()] + [int] $ScanAgentId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Controls if new hosts should be discovered for new host scans", - Position=12)] + [parameter(Mandatory=$false,HelpMessage="Controls if new hosts should be discovered for new host scans",Position=12)] [switch] $DiscoverSubnet, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Marks subnet as used", - Position=12)] + [parameter(Mandatory=$false,HelpMessage="Marks subnet as used",Position=12)] [switch] $IsFull, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Assignes state (tag) to subnet (default: 1 Used)", - Position=12)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",Position=12)] + [ValidateNotNullOrEmpty()] + [int] $TagId, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Subnet threshold", - Position=13)] - [ValidateScript({ $_ -match "^\d+$" -and $_ -le 100 -and $_ -ge 1 })] + [parameter(Mandatory=$false,HelpMessage="Subnet threshold",Position=13)] + [ValidateScript({ $_ -le 100 -and $_ -ge 1 })] + [ValidateNotNullOrEmpty()] + [int] $Threshold, - [parameter( - Mandatory=$false, - ValueFromPipeline=$true, - ValueFromPipelineByPropertyName=$true, - HelpMessage="Location index", - Position=14)] - [ValidateScript({ $_ -match "^\d+$" })] - [string] + [parameter(Mandatory=$false,HelpMessage="Location index",Position=14)] + [ValidateNotNullOrEmpty()] + [int] $LocationId, - [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)] [ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })] + [ValidateNotNullOrEmpty()] $CustomFields ) process { diff --git a/functions/public/Remove-Address.ps1 b/functions/public/Remove-Address.ps1 index 536d14d..07a5a07 100644 --- a/functions/public/Remove-Address.ps1 +++ b/functions/public/Remove-Address.ps1 @@ -17,8 +17,8 @@ function Remove-Address { } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_identifiers = @($Id);break } - "ByAddressObject" { $_identifiers = @($AddressObject.Id);break } + "ByID" { $_identifiers = @($Id); break } + "ByAddressObject" { $_identifiers = @($AddressObject.Id); break } } $_params.Add("Identifiers",$_identifiers) diff --git a/functions/public/Set-Address.ps1 b/functions/public/Set-Address.ps1 index 934de3d..f47ef10 100644 --- a/functions/public/Set-Address.ps1 +++ b/functions/public/Set-Address.ps1 @@ -61,12 +61,12 @@ function Set-Address { ) process { $_params = @{ - Controller = "addresses" + Controller = [PS.IPAM.controllers]::addresses Method = "PATCH" } switch ($PSCmdlet.ParameterSetName) { - "ByID" { $_id = $Id;break } - "ByAddressObject" { $_id = $AddressObject.id;break } + "ByID" { $_id = $Id; break } + "ByAddressObject" { $_id = $AddressObject.id; break } } $_identifiers = @($_id)