From 65e49e825dd30a68d9914b678d52d41f59ea6ee2 Mon Sep 17 00:00:00 2001 From: Pascal Liehne Date: Sun, 1 Sep 2024 21:00:17 +0200 Subject: [PATCH] add Remove-NetboxVirtualMachinedisk --- .../Remove-NetboxVirtualMachinedisk.ps1 | 55 +++++++++++++++++ NetboxPS.psd1 | 26 ++++---- NetboxPS/NetboxPS.psd1 | 26 ++++---- NetboxPS/NetboxPS.psm1 | 60 +++++++++++++++++++ 4 files changed, 141 insertions(+), 26 deletions(-) create mode 100644 Functions/Virtualization/VirtualMachinedisk/Remove-NetboxVirtualMachinedisk.ps1 diff --git a/Functions/Virtualization/VirtualMachinedisk/Remove-NetboxVirtualMachinedisk.ps1 b/Functions/Virtualization/VirtualMachinedisk/Remove-NetboxVirtualMachinedisk.ps1 new file mode 100644 index 0000000..6b436da --- /dev/null +++ b/Functions/Virtualization/VirtualMachinedisk/Remove-NetboxVirtualMachinedisk.ps1 @@ -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 { + + } +} diff --git a/NetboxPS.psd1 b/NetboxPS.psd1 index 88feaa4..a259e6a 100644 --- a/NetboxPS.psd1 +++ b/NetboxPS.psd1 @@ -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 = @() diff --git a/NetboxPS/NetboxPS.psd1 b/NetboxPS/NetboxPS.psd1 index 88feaa4..a259e6a 100644 --- a/NetboxPS/NetboxPS.psd1 +++ b/NetboxPS/NetboxPS.psd1 @@ -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 = @() diff --git a/NetboxPS/NetboxPS.psm1 b/NetboxPS/NetboxPS.psm1 index 8abd8ff..f6339d2 100644 --- a/NetboxPS/NetboxPS.psm1 +++ b/NetboxPS/NetboxPS.psm1 @@ -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 {