NetboxPS/Functions/Virtualization/VirtualMachineInterface/Set-NetboxVirtualMachineInterface.ps1

52 lines
1.4 KiB
PowerShell
Raw Normal View History

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

2020-03-23 12:18:01 -04:00
function Set-NetboxVirtualMachineInterface {
[CmdletBinding(ConfirmImpact = 'Medium',
SupportsShouldProcess = $true)]
[OutputType([pscustomobject])]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
2023-07-28 16:17:23 -04:00
[uint64[]]$Id,
2020-03-23 12:18:01 -04:00
[string]$Name,
2020-03-23 12:18:01 -04:00
[string]$MAC_Address,
2020-03-23 12:18:01 -04:00
[uint16]$MTU,
2020-03-23 12:18:01 -04:00
[string]$Description,
2020-03-23 12:18:01 -04:00
[boolean]$Enabled,
[uint64]$Virtual_Machine,
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 ($VMI_ID in $Id) {
Write-Verbose "Obtaining VM Interface..."
$CurrentVMI = Get-NetboxVirtualMachineInterface -Id $VMI_ID -ErrorAction Stop
Write-Verbose "Finished obtaining VM Interface"
2020-03-23 12:18:01 -04:00
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'interfaces', $CurrentVMI.Id))
2020-03-23 12:18:01 -04:00
if ($Force -or $pscmdlet.ShouldProcess("Interface $($CurrentVMI.Id) on VM $($CurrentVMI.Virtual_Machine.Name)", "Set")) {
$URIComponents = BuildURIComponents -URISegments $Segments -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
}
}