add Remove-NetboxVirtualMachinedisk

This commit is contained in:
Pascal Liehne 2024-09-01 21:00:17 +02:00
parent 5a72501be2
commit 65e49e825d
4 changed files with 141 additions and 26 deletions

View file

@ -0,0 +1,55 @@

function Remove-NetboxVirtualMachineDisk {
<#
.SYNOPSIS
Delete a virtual machine disk
.DESCRIPTION
Deletes a virtual machine disk from Netbox by ID
.PARAMETER Id
Database ID of the virtual machine disk
.PARAMETER Force
Force deletion without any prompts
.EXAMPLE
PS C:\> Remove-NetboxVirtualMachineDisk -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($DiskId in $Id) {
$CurrentDisk = Get-NetboxVirtualMachineDisk -Id $DiskId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDisk.Name)/$($CurrentDisk.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks', $CurrentDisk.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}

View file

@ -105,19 +105,19 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-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',
'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme',
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
'Test-NetboxAPIConnected', 'ThrowNetboxRESTError',
'VerifyAPIConnectivity'
'Remove-NetboxVirtualMachinedisk', 'Set-NetboxCipherSSL',
'Set-NetboxContact', 'Set-NetboxContactAssignment',
'Set-NetboxContactRole', 'Set-NetboxCredential',
'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort',
'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection',
'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort',
'Set-NetboxHostScheme', 'Set-NetboxInvokeParams',
'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange',
'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout',
'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine',
'Set-NetboxVirtualMachinedisk', 'Set-NetboxVirtualMachineInterface',
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected',
'ThrowNetboxRESTError', 'VerifyAPIConnectivity'
# Cmdlets 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 cmdlets to export.
CmdletsToExport = @()

View file

@ -105,19 +105,19 @@ FunctionsToExport = 'Add-NetboxDCIMFrontPort', 'Add-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',
'Set-NetboxHostName', 'Set-NetboxHostPort', 'Set-NetboxHostScheme',
'Set-NetboxInvokeParams', 'Set-NetboxIPAMAddress',
'Set-NetboxIPAMAddressRange', 'Set-NetboxIPAMPrefix',
'Set-NetboxTimeout', 'Set-NetboxUnstrustedSSL',
'Set-NetboxVirtualMachine', 'Set-NetboxVirtualMachinedisk',
'Set-NetboxVirtualMachineInterface', 'SetupNetboxConfigVariable',
'Test-NetboxAPIConnected', 'ThrowNetboxRESTError',
'VerifyAPIConnectivity'
'Remove-NetboxVirtualMachinedisk', 'Set-NetboxCipherSSL',
'Set-NetboxContact', 'Set-NetboxContactAssignment',
'Set-NetboxContactRole', 'Set-NetboxCredential',
'Set-NetboxDCIMDevice', 'Set-NetboxDCIMFrontPort',
'Set-NetboxDCIMInterface', 'Set-NetboxDCIMInterfaceConnection',
'Set-NetboxDCIMRearPort', 'Set-NetboxHostName', 'Set-NetboxHostPort',
'Set-NetboxHostScheme', 'Set-NetboxInvokeParams',
'Set-NetboxIPAMAddress', 'Set-NetboxIPAMAddressRange',
'Set-NetboxIPAMPrefix', 'Set-NetboxTimeout',
'Set-NetboxUnstrustedSSL', 'Set-NetboxVirtualMachine',
'Set-NetboxVirtualMachinedisk', 'Set-NetboxVirtualMachineInterface',
'SetupNetboxConfigVariable', 'Test-NetboxAPIConnected',
'ThrowNetboxRESTError', 'VerifyAPIConnectivity'
# Cmdlets 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 cmdlets to export.
CmdletsToExport = @()

View file

@ -5148,6 +5148,66 @@ function Remove-NetboxVirtualMachine {
#endregion
#region File Remove-NetboxVirtualMachinedisk.ps1
function Remove-NetboxVirtualMachineDisk {
<#
.SYNOPSIS
Delete a virtual machine disk
.DESCRIPTION
Deletes a virtual machine disk from Netbox by ID
.PARAMETER Id
Database ID of the virtual machine disk
.PARAMETER Force
Force deletion without any prompts
.EXAMPLE
PS C:\> Remove-NetboxVirtualMachineDisk -Id $value1
.NOTES
Additional information about the function.
#>
[CmdletBinding(ConfirmImpact = 'High',
SupportsShouldProcess = $true)]
param
(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true)]
[uint64[]]$Id,
[switch]$Force
)
begin {
}
process {
foreach ($DiskId in $Id) {
$CurrentDisk = Get-NetboxVirtualMachineDisk -Id $DiskId -ErrorAction Stop
if ($Force -or $pscmdlet.ShouldProcess("$($CurrentDisk.Name)/$($CurrentDisk.Id)", "Remove")) {
$Segments = [System.Collections.ArrayList]::new(@('virtualization', 'virtual-disks', $CurrentDisk.Id))
$URI = BuildNewURI -Segments $Segments
InvokeNetboxRequest -URI $URI -Method DELETE
}
}
}
end {
}
}
#endregion
#region File Set-NetboxCipherSSL.ps1
Function Set-NetboxCipherSSL {