NetboxPS/Functions/DCIM/Devices/Set-NetboxDCIMDevice.ps1

77 lines
1.5 KiB
PowerShell
Raw Normal View History

2022-12-06 13:34:52 -05:00

2020-03-23 12:18:01 -04:00
function Set-NetboxDCIMDevice {
[CmdletBinding(SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint16[]]$Id,
2020-03-23 12:18:01 -04:00
[string]$Name,
2020-03-23 12:18:01 -04:00
[object]$Device_Role,
2020-03-23 12:18:01 -04:00
[object]$Device_Type,
[uint64]$Site,
2020-03-23 12:18:01 -04:00
[object]$Status,
[uint64]$Platform,
[uint64]$Tenant,
[uint64]$Cluster,
[uint64]$Rack,
2020-03-23 12:18:01 -04:00
[uint16]$Position,
2020-03-23 12:18:01 -04:00
[object]$Face,
2020-03-23 12:18:01 -04:00
[string]$Serial,
2020-03-23 12:18:01 -04:00
[string]$Asset_Tag,
[uint64]$Virtual_Chassis,
[uint64]$VC_Priority,
[uint64]$VC_Position,
[uint64]$Primary_IP4,
[uint64]$Primary_IP6,
2020-03-23 12:18:01 -04:00
[string]$Comments,
2020-03-23 12:18:01 -04:00
[hashtable]$Custom_Fields,
2020-03-23 12:18:01 -04:00
[switch]$Force
)
2020-03-23 12:18:01 -04:00
begin {
2020-03-23 12:18:01 -04:00
}
2020-03-23 12:18:01 -04:00
process {
foreach ($DeviceID in $Id) {
$CurrentDevice = Get-NetboxDCIMDevice -Id $DeviceID -ErrorAction Stop
2020-03-23 12:18:01 -04:00
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDevice.Name)", "Set")) {
$Segments = [System.Collections.ArrayList]::new(@('dcim', 'devices', $CurrentDevice.Id))
2020-03-23 12:18:01 -04:00
$URIComponents = BuildURIComponents -URISegments $Segments.Clone() -ParametersDictionary $PSBoundParameters -SkipParameterByName 'Id', 'Force'
2020-03-23 12:18:01 -04:00
$URI = BuildNewURI -Segments $URIComponents.Segments
2020-03-23 12:18:01 -04:00
InvokeNetboxRequest -URI $URI -Body $URIComponents.Parameters -Method PATCH
}
}
}
2020-03-23 12:18:01 -04:00
end {
2020-03-23 12:18:01 -04:00
}
}