diff --git a/Functions/DCIM/Platform/Add-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Platform/Add-NetboxDCIMPlatform.ps1 new file mode 100644 index 0000000..d005399 --- /dev/null +++ b/Functions/DCIM/Platform/Add-NetboxDCIMPlatform.ps1 @@ -0,0 +1,34 @@ +function Add-NetboxDCIMPlatform { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [string]$Name, + + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [uint64]$Manufacturer, + + [uint64]$Config_Template, + + [string]$Description, + + [uint16[]]$Tags + + ) + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms')) + + if (-not $PSBoundParameters.ContainsKey('slug')) { + $PSBoundParameters.Add('slug', $($name | Get-NetboxSlug)) + } + + $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/Get-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Platform/Get-NetboxDCIMPlatform.ps1 similarity index 100% rename from Functions/DCIM/Get-NetboxDCIMPlatform.ps1 rename to Functions/DCIM/Platform/Get-NetboxDCIMPlatform.ps1 diff --git a/Functions/DCIM/Platform/Remove-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Platform/Remove-NetboxDCIMPlatform.ps1 new file mode 100644 index 0000000..78af25d --- /dev/null +++ b/Functions/DCIM/Platform/Remove-NetboxDCIMPlatform.ps1 @@ -0,0 +1,35 @@ +function Remove-NetboxDCIMPlatform { + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint64[]]$Id, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($PlatformID in $Id) { + $CurrentPlatform = Get-NetboxDCIMPlatform -Id $PlatformID -ErrorAction Stop + + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPlatform.Name) | ID: $($CurrentPlatform.Id)", "Remove")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + } + + end { + + } +} \ No newline at end of file diff --git a/Functions/DCIM/Platform/Set-NetboxDCIMPlatform.ps1 b/Functions/DCIM/Platform/Set-NetboxDCIMPlatform.ps1 new file mode 100644 index 0000000..0e869a7 --- /dev/null +++ b/Functions/DCIM/Platform/Set-NetboxDCIMPlatform.ps1 @@ -0,0 +1,51 @@ +function Set-NetboxDCIMPlatform { + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint64[]]$Id, + + [string]$Name, + + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [uint64]$Manufacturer, + + [uint64]$Config_Template, + + [string]$Description, + + [uint64[]]$Tags, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($FrontPortID in $Id) { + $CurrentPlatform = Get-NetboxDCIMPlatform -Id $FrontPortID -ErrorAction Stop + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $URI = BuildNewURI -Segments $Segments + + if ($Force -or $pscmdlet.ShouldProcess("Platform ID $($CurrentPlatform.Id)", "Set")) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } + } + } + + end { + + } +} \ No newline at end of file diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 22fc1f7..4192696 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 01/09/2024 +# Generated on: 10/5/2024 # @{ @@ -70,9 +70,9 @@ CLRVersion = '2.0.50727' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', - 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', + 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMPlatform', + 'Add-NetboxDCIMRearPort', 'Add-NetboxVirtualMachineInterface', + 'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected', 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', @@ -90,8 +90,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxIPAMAddress', 'Get-NetboxIPAMAddressRange', 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', - 'Get-NetboxObjectType', 'Get-NetboxTag', 'Get-NetboxTenant', - 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxObjectType', 'Get-NetboxSlug', 'Get-NetboxTag', + 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', @@ -102,14 +102,15 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMFrontPort', 'Remove-NetboxDCIMInterface', - 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', - 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', - 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', - 'Set-NetboxCipherSSL', 'Set-NetboxContact', - 'Set-NetboxContactAssignment', 'Set-NetboxContactRole', - 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', - 'Set-NetboxDCIMFrontPort', 'Set-NetboxDCIMInterface', - 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxDCIMRearPort', + 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMPlatform', + 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMSite', + 'Remove-NetboxIPAMAddress', 'Remove-NetboxIPAMAddressRange', + 'Remove-NetboxVirtualMachine', 'Set-NetboxCipherSSL', + 'Set-NetboxContact', 'Set-NetboxContactAssignment', + 'Set-NetboxContactRole', 'Set-NetboxCredential', + 'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort', + 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', + 'Set-NetboxDCIMPlatform', 'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 22fc1f7..4192696 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -3,7 +3,7 @@ # # Generated by: Ben Claussen # -# Generated on: 01/09/2024 +# Generated on: 10/5/2024 # @{ @@ -70,9 +70,9 @@ CLRVersion = '2.0.50727' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', - 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMRearPort', - 'Add-NetboxVirtualMachineInterface', 'BuildNewURI', - 'BuildURIComponents', 'CheckNetboxIsConnected', + 'Add-NetboxDCIMInterfaceConnection', 'Add-NetboxDCIMPlatform', + 'Add-NetboxDCIMRearPort', 'Add-NetboxVirtualMachineInterface', + 'BuildNewURI', 'BuildURIComponents', 'CheckNetboxIsConnected', 'Clear-NetboxCredential', 'Connect-NetboxAPI', 'CreateEnum', 'Get-ModelDefinition', 'Get-NetboxAPIDefinition', 'GetNetboxAPIErrorBody', 'Get-NetboxCircuit', @@ -90,8 +90,8 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'Get-NetboxIPAMAddress', 'Get-NetboxIPAMAddressRange', 'Get-NetboxIPAMAggregate', 'Get-NetboxIPAMAvailableIP', 'Get-NetboxIPAMPrefix', 'Get-NetboxIPAMRole', 'Get-NetboxIPAMVLAN', - 'Get-NetboxObjectType', 'Get-NetboxTag', 'Get-NetboxTenant', - 'Get-NetboxTimeout', 'Get-NetboxVersion', + 'Get-NetboxObjectType', 'Get-NetboxSlug', 'Get-NetboxTag', + 'Get-NetboxTenant', 'Get-NetboxTimeout', 'Get-NetboxVersion', 'Get-NetboxVirtualizationCluster', 'Get-NetboxVirtualizationClusterGroup', 'Get-NetboxVirtualMachine', 'Get-NetboxVirtualMachineInterface', 'InvokeNetboxRequest', @@ -102,14 +102,15 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-NetboxDCIMInterface', 'New-NetboxIPAMVLAN', 'New-NetboxTenant', 'New-NetboxVirtualMachine', 'Remove-NetboxDCIMDevice', 'Remove-NetboxDCIMFrontPort', 'Remove-NetboxDCIMInterface', - 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMRearPort', - 'Remove-NetboxDCIMSite', 'Remove-NetboxIPAMAddress', - 'Remove-NetboxIPAMAddressRange', 'Remove-NetboxVirtualMachine', - 'Set-NetboxCipherSSL', 'Set-NetboxContact', - 'Set-NetboxContactAssignment', 'Set-NetboxContactRole', - 'Set-NetboxCredential', 'Set-NetboxDCIMDevice', - 'Set-NetboxDCIMFrontPort', 'Set-NetboxDCIMInterface', - 'Set-NetboxDCIMInterfaceConnection', 'Set-NetboxDCIMRearPort', + 'Remove-NetboxDCIMInterfaceConnection', 'Remove-NetboxDCIMPlatform', + 'Remove-NetboxDCIMRearPort', 'Remove-NetboxDCIMSite', + 'Remove-NetboxIPAMAddress', 'Remove-NetboxIPAMAddressRange', + 'Remove-NetboxVirtualMachine', 'Set-NetboxCipherSSL', + 'Set-NetboxContact', 'Set-NetboxContactAssignment', + 'Set-NetboxContactRole', 'Set-NetboxCredential', + 'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort', + 'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection', + 'Set-NetboxDCIMPlatform', 'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme', 'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix', diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index f8e63e0..7eb2475 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -177,6 +177,45 @@ function Add-NetboxDCIMInterfaceConnection { #endregion +#region File Add-NetboxDCIMPlatform.ps1 + +function Add-NetboxDCIMPlatform { + [CmdletBinding()] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true)] + [string]$Name, + + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [uint64]$Manufacturer, + + [uint64]$Config_Template, + + [string]$Description, + + [uint16[]]$Tags + + ) + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms')) + + if (-not $PSBoundParameters.ContainsKey('slug')) { + $PSBoundParameters.Add('slug', $($name | Get-NetboxSlug)) + } + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters + + $URI = BuildNewURI -Segments $URIComponents.Segments + + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method POST +} + +#endregion + #region File Add-NetboxDCIMRearPort.ps1 function Add-NetboxDCIMRearPort { @@ -2910,6 +2949,27 @@ function Get-NetboxObjectType { #endregion +#region File Get-NetboxSlug.ps1 + +function Get-NetboxSlug { + param ( + [Parameter(ValueFromPipeline)] + [string]$slug, + + [uint16]$chars = 100 + ) + + process { + return $slug -replace '[^\-.\w\s]', '' ` + -replace '[^a-zA-Z0-9-_ ]', '' ` + -replace '^[\s.]+|[\s.]+$', '' ` + -replace '[-.\s]+', '-' ` + | ForEach-Object { $_.ToLower().Substring(0, [Math]::Min($_.Length, $chars)) } + } +} + +#endregion + #region File Get-NetboxTag.ps1 @@ -4762,6 +4822,46 @@ function Remove-NetboxDCIMInterfaceConnection { #endregion +#region File Remove-NetboxDCIMPlatform.ps1 + +function Remove-NetboxDCIMPlatform { + + [CmdletBinding(ConfirmImpact = 'High', + SupportsShouldProcess = $true)] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint64[]]$Id, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($PlatformID in $Id) { + $CurrentPlatform = Get-NetboxDCIMPlatform -Id $PlatformID -ErrorAction Stop + + if ($Force -or $pscmdlet.ShouldProcess("Name: $($CurrentPlatform.Name) | ID: $($CurrentPlatform.Id)", "Remove")) { + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id)) + + $URI = BuildNewURI -Segments $Segments + + InvokeNetboxRequest -URI $URI -Method DELETE + } + } + } + + end { + + } +} + +#endregion + #region File Remove-NetboxDCIMRearPort.ps1 function Remove-NetboxDCIMRearPort { @@ -5703,6 +5803,62 @@ function Set-NetboxDCIMInterfaceConnection { #endregion +#region File Set-NetboxDCIMPlatform.ps1 + +function Set-NetboxDCIMPlatform { + [CmdletBinding(ConfirmImpact = 'Medium', + SupportsShouldProcess = $true)] + [OutputType([pscustomobject])] + param + ( + [Parameter(Mandatory = $true, + ValueFromPipelineByPropertyName = $true)] + [uint64[]]$Id, + + [string]$Name, + + [ValidateLength(1, 100)] + [ValidatePattern('^[-a-zA-Z0-9_]+$')] + [string]$Slug, + + [uint64]$Manufacturer, + + [uint64]$Config_Template, + + [string]$Description, + + [uint64[]]$Tags, + + [switch]$Force + ) + + begin { + + } + + process { + foreach ($FrontPortID in $Id) { + $CurrentPlatform = Get-NetboxDCIMPlatform -Id $FrontPortID -ErrorAction Stop + + $Segments = [System.Collections.ArrayList]::new(@('dcim', 'platforms', $CurrentPlatform.Id)) + + $URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id' + + $URI = BuildNewURI -Segments $Segments + + if ($Force -or $pscmdlet.ShouldProcess("Platform ID $($CurrentPlatform.Id)", "Set")) { + InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH + } + } + } + + end { + + } +} + +#endregion + #region File Set-NetboxDCIMRearPort.ps1