diff --git a/.vscode/settings.json b/.vscode/settings.json index cc82cf9..1f7f861 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,5 +6,6 @@ "powershell.codeFormatting.newLineAfterCloseBrace": false, "[markdown]": { "files.trimTrailingWhitespace": false, - } + }, + "powershell.codeFormatting.openBraceOnSameLine": true } \ No newline at end of file diff --git a/Functions/DCIM/Cable Terminations/Get-NetboxDCIMCableTermination.ps1 b/Functions/DCIM/Cable Terminations/Get-NetboxDCIMCableTermination.ps1 new file mode 100644 index 0000000..0052a47 --- /dev/null +++ b/Functions/DCIM/Cable Terminations/Get-NetboxDCIMCableTermination.ps1 @@ -0,0 +1,35 @@ +function Get-NetboxDCIMCableTermination { + [CmdletBinding()] + #region Parameters + param + ( + [uint16]$Limit, + + [uint16]$Offset, + + [Parameter(ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [uint16]$Cable, + + [string]$Cable_End, + + [string]$Termination_Type, + + [uint16]$Termination_ID, + + [switch]$Raw + ) + + #endregion Parameters + + process { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'cable-terminations')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } +} \ No newline at end of file diff --git a/Functions/DCIM/Cables/Get-NetboxDCIMCable.ps1 b/Functions/DCIM/Cables/Get-NetboxDCIMCable.ps1 new file mode 100644 index 0000000..b62fc87 --- /dev/null +++ b/Functions/DCIM/Cables/Get-NetboxDCIMCable.ps1 @@ -0,0 +1,55 @@ +function Get-NetboxDCIMCable { + [CmdletBinding()] + #region Parameters + param + ( + [uint16]$Limit, + + [uint16]$Offset, + + [Parameter(ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [string]$Label, + + [string]$Termination_A_Type, + + [uint16]$Termination_A_ID, + + [string]$Termination_B_Type, + + [UInt16]$Termination_B_ID, + + [string]$Type, + + [string]$Status, + + [string]$Color, + + [UInt16]$Device_ID, + + [string]$Device, + + [uint16]$Rack_Id, + + [string]$Rack, + + [uint16]$Location_ID, + + [string]$Location, + + [switch]$Raw + ) + + #endregion Parameters + + process { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'cables')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Raw' + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } +} \ No newline at end of file diff --git a/Functions/DCIM/FrontPorts/Add-NetboxDCIMFrontPort.ps1 b/Functions/DCIM/FrontPorts/Add-NetboxDCIMFrontPort.ps1 new file mode 100644 index 0000000..27515e8 --- /dev/null +++ b/Functions/DCIM/FrontPorts/Add-NetboxDCIMFrontPort.ps1 @@ -0,0 +1,42 @@ +function Add-NetboxDCIMFrontPort { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [uint16]$Device, + + [uint16]$Module, + + [Parameter(Mandatory = $true)] + [string]$Name, + + [string]$Label, + + [Parameter(Mandatory = $true)] + [string]$Type, + + [ValidatePattern('^[0-9a-f]{6}$')] + [string]$Color, + + [Parameter(Mandatory = $true)] + [uint16]$Rear_Port, + + [uint16]$Rear_Port_Position, + + [string]$Description, + + [bool]$Mark_Connected, + + [uint16[]]$Tags + + ) + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST +} \ No newline at end of file diff --git a/Functions/DCIM/FrontPorts/Get-NetboxDCIMFrontPort.ps1 b/Functions/DCIM/FrontPorts/Get-NetboxDCIMFrontPort.ps1 new file mode 100644 index 0000000..7066d70 --- /dev/null +++ b/Functions/DCIM/FrontPorts/Get-NetboxDCIMFrontPort.ps1 @@ -0,0 +1,34 @@ +function Get-NetboxDCIMFrontPort { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [uint16]$Limit, + + [uint16]$Offset, + + [Parameter(ValueFromPipelineByPropertyName = $true)] + [uint16]$Id, + + [string]$Name, + + [string]$Device, + + [uint16]$Device_Id, + + [string]$Type, + + [switch]$Raw + ) + + process { + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } +} \ No newline at end of file diff --git a/Functions/DCIM/FrontPorts/Remove-NetboxDCIMFrontPort.ps1 b/Functions/DCIM/FrontPorts/Remove-NetboxDCIMFrontPort.ps1 new file mode 100644 index 0000000..53a68f7 --- /dev/null +++ b/Functions/DCIM/FrontPorts/Remove-NetboxDCIMFrontPort.ps1 @@ -0,0 +1,35 @@ +function Remove-NetboxDCIMFrontPort { + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($FrontPortID in $Id) { + $CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop + + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + } + + end { + + } +} \ No newline at end of file diff --git a/Functions/DCIM/FrontPorts/Set-NetboxDCIMFrontPort.ps1 b/Functions/DCIM/FrontPorts/Set-NetboxDCIMFrontPort.ps1 new file mode 100644 index 0000000..c9812f8 --- /dev/null +++ b/Functions/DCIM/FrontPorts/Set-NetboxDCIMFrontPort.ps1 @@ -0,0 +1,60 @@ +function Set-NetboxDCIMFrontPort { + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [uint16]$Device, + + [uint16]$Module, + + [string]$Name, + + [string]$Label, + + [string]$Type, + + [ValidatePattern('^[0-9a-f]{6}$')] + [string]$Color, + + [uint16]$Rear_Port, + + [uint16]$Rear_Port_Position, + + [string]$Description, + + [bool]$Mark_Connected, + + [uint16[]]$Tags, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($FrontPortID in $Id) { + $CurrentPort = Get-NetboxDCIMFrontPort -Id $FrontPortID -ErrorAction Stop + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'front-ports', $CurrentPort.Id)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $URI = BuildNewURI -Segments $Segments + + if ($Force -or $pscmdlet.ShouldProcess("Front Port ID $($CurrentPort.Id)", "Set")) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } + } + } + + end { + + } +} \ No newline at end of file diff --git a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 index 730e776..de7de00 100644 --- a/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Get-NetboxDCIMInterface.ps1 @@ -1,5 +1,4 @@ - -function Get-NetboxDCIMInterface { +function Get-NetboxDCIMInterface { [CmdletBinding()] [OutputType([pscustomobject])] param diff --git a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 index 8824b4c..1eff61d 100644 --- a/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Remove-NetboxDCIMInterface.ps1 @@ -1,6 +1,5 @@ - -function Remove-NetboxDCIMInterface { -<# +function Remove-NetboxDCIMInterface { + <# .SYNOPSIS Removes an interface @@ -21,11 +20,11 @@ function Remove-NetboxDCIMInterface { #> [CmdletBinding(ConfirmImpact = 'High', - SupportsShouldProcess = $true)] + SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $true, - ValueFromPipelineByPropertyName = $true)] + ValueFromPipelineByPropertyName = $true)] [uint16[]]$Id, [switch]$Force diff --git a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 index 566c1a0..8d7c4c1 100644 --- a/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 +++ b/Functions/DCIM/Interfaces/Set-NetboxDCIMInterface.ps1 @@ -1,5 +1,4 @@ - -function Set-NetboxDCIMInterface { +function Set-NetboxDCIMInterface { [CmdletBinding(ConfirmImpact = 'Medium', SupportsShouldProcess = $true)] [OutputType([pscustomobject])] @@ -37,7 +36,9 @@ function Set-NetboxDCIMInterface { [uint16]$Untagged_VLAN, [ValidateRange(1, 4094)] - [uint16[]]$Tagged_VLANs + [uint16[]]$Tagged_VLANs, + + [switch]$Force ) begin { diff --git a/Functions/DCIM/RearPorts/Add-NetboxDCIMRearPort.ps1 b/Functions/DCIM/RearPorts/Add-NetboxDCIMRearPort.ps1 new file mode 100644 index 0000000..aed9896 --- /dev/null +++ b/Functions/DCIM/RearPorts/Add-NetboxDCIMRearPort.ps1 @@ -0,0 +1,48 @@ +function Add-NetboxDCIMRearPort { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [uint16]$Device, + + [uint16]$Module, + + [Parameter(Mandatory = $true)] + [string]$Name, + + [string]$Label, + + [Parameter(Mandatory = $true)] + [string]$Type, + + [ValidatePattern('^[0-9a-f]{6}$')] + [string]$Color, + + [uint16]$Positions = 1, + + [string]$Description, + + [bool]$Mark_Connected, + + [uint16[]]$Tags + ) + + begin { + + } + + process { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST + } + + end { + + } +} \ No newline at end of file diff --git a/Functions/DCIM/RearPorts/Get-NetboxDCIMRearPort.ps1 b/Functions/DCIM/RearPorts/Get-NetboxDCIMRearPort.ps1 new file mode 100644 index 0000000..b6ee23b --- /dev/null +++ b/Functions/DCIM/RearPorts/Get-NetboxDCIMRearPort.ps1 @@ -0,0 +1,34 @@ +function Get-NetboxDCIMRearPort { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [uint16]$Limit, + + [uint16]$Offset, + + [Parameter(ValueFromPipelineByPropertyName = $true)] + [uint16]$Id, + + [string]$Name, + + [string]$Device, + + [uint16]$Device_Id, + + [string]$Type, + + [switch]$Raw + ) + + process { + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } +} \ No newline at end of file diff --git a/Functions/DCIM/RearPorts/Remove-NetboxDCIMRearPort.ps1 b/Functions/DCIM/RearPorts/Remove-NetboxDCIMRearPort.ps1 new file mode 100644 index 0000000..7a301ec --- /dev/null +++ b/Functions/DCIM/RearPorts/Remove-NetboxDCIMRearPort.ps1 @@ -0,0 +1,35 @@ +function Remove-NetboxDCIMRearPort { + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($RearPortID in $Id) { + $CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop + + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPort.Name) | ID: $($CurrentPort.Id)", "Remove")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + } + + end { + + } +} \ No newline at end of file diff --git a/Functions/DCIM/RearPorts/Set-NetboxDCIMRearPort.ps1 b/Functions/DCIM/RearPorts/Set-NetboxDCIMRearPort.ps1 new file mode 100644 index 0000000..79dd895 --- /dev/null +++ b/Functions/DCIM/RearPorts/Set-NetboxDCIMRearPort.ps1 @@ -0,0 +1,65 @@ + +function Set-NetboxDCIMRearPort +{ + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint16[]]$Id, + + [uint16]$Device, + + [uint16]$Module, + + [string]$Name, + + [string]$Label, + + [string]$Type, + + [ValidatePattern('^[0-9a-f]{6}$')] + [string]$Color, + + [uint16]$Positions, + + [string]$Description, + + [bool]$Mark_Connected, + + [uint16[]]$Tags, + + [switch]$Force + ) + + begin + { + + } + + process + { + foreach ($RearPortID in $Id) + { + $CurrentPort = Get-NetboxDCIMRearPort -Id $RearPortID -ErrorAction Stop + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'rear-ports', $CurrentPort.Id)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $URI = BuildNewURI -Segments $Segments + + if ($Force -or $pscmdlet.ShouldProcess("Rear Port ID $($CurrentPort.Id)", "Set")) + { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } + } + } + + end + { + + } +} \ No newline at end of file diff --git a/Functions/Extras/Get-NetboxTag.ps1 b/Functions/Extras/Get-NetboxTag.ps1 new file mode 100644 index 0000000..5ea4225 --- /dev/null +++ b/Functions/Extras/Get-NetboxTag.ps1 @@ -0,0 +1,31 @@ + +function Get-NetboxTag { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [uint16]$Limit, + + [uint16]$Offset, + + [Parameter(ValueFromPipelineByPropertyName = $true)] + [uint16]$Id, + + [string]$Name, + + [string]$Slug, + + [switch]$Raw + ) + + process { + + $Segments = [System.Collections.ArrayList]::new(@('extras', 'tags')) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments -Parameters $URIComponents.Parameters + + InvokeNetboxRequest -URI $URI -Raw:$Raw + } +} \ No newline at end of file diff --git a/Postman/Netbox.postman_collection.json b/Postman/Netbox.postman_collection.json index 427c372..645362b 100644 --- a/Postman/Netbox.postman_collection.json +++ b/Postman/Netbox.postman_collection.json @@ -953,6 +953,50 @@ }, "response": [] }, + { + "name": "Get Device Rear Ports", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/rear-ports/", + "protocol": "{{SCHEME}}", + "host": [ + "{{HOSTNAME}}" + ], + "port": "{{PORT}}", + "path": [ + "api", + "dcim", + "rear-ports", + "" + ] + } + }, + "response": [] + }, + { + "name": "Get Device Front Ports", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/front-ports/", + "protocol": "{{SCHEME}}", + "host": [ + "{{HOSTNAME}}" + ], + "port": "{{PORT}}", + "path": [ + "api", + "dcim", + "rear-ports", + "" + ] + } + }, + "response": [] + }, { "name": "Add Interface", "request": { @@ -983,6 +1027,64 @@ } }, "response": [] + }, + { + "name": "Add Rear Port", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\r\n \"device\": 62,\r\n \"name\": \"RearPort1\",\r\n \"type\": 110-punch\r\n}" + }, + "url": { + "raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/dcim/rear-ports/", + "protocol": "{{SCHEME}}", + "host": [ + "{{HOSTNAME}}" + ], + "port": "{{PORT}}", + "path": [ + "api", + "dcim", + "rear-ports", + "" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Extras", + "item": [ + { + "name": "Get Tags", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{SCHEME}}://{{HOSTNAME}}:{{PORT}}/api/extras/tags/", + "protocol": "{{SCHEME}}", + "host": [ + "{{HOSTNAME}}" + ], + "port": "{{PORT}}", + "path": [ + "api", + "extras", + "tags", + "" + ] + } + }, + "response": [] } ] },