using System;
using System.Management.Automation;
using PSProxmox.Client;
using PSProxmox.Session;
namespace PSProxmox.Cmdlets
{
///
/// Removes a storage from Proxmox VE.
/// The Remove-ProxmoxStorage cmdlet removes a storage from Proxmox VE.
///
/// Remove a storage
/// Remove-ProxmoxStorage -Connection $connection -Name "backup"
///
///
/// Remove a storage using pipeline input
/// Get-ProxmoxStorage -Connection $connection -Name "backup" | Remove-ProxmoxStorage -Connection $connection
///
///
[Cmdlet(VerbsCommon.Remove, "ProxmoxStorage", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)]
public class RemoveProxmoxStorageCmdlet : PSCmdlet
{
///
/// The connection to the Proxmox VE server.
///
[Parameter(Mandatory = true, Position = 0)]
public ProxmoxConnection Connection { get; set; }
///
/// The name of the storage to remove.
///
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true)]
public string Name { get; set; }
///
/// Processes the cmdlet.
///
protected override void ProcessRecord()
{
try
{
var client = new ProxmoxApiClient(Connection, this);
// Confirm removal
if (!ShouldProcess($"Storage {Name}", "Remove"))
{
return;
}
// Remove the storage
WriteVerbose($"Removing storage {Name}");
client.Delete($"storage/{Name}");
WriteVerbose($"Storage {Name} removed");
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "RemoveProxmoxStorageError", ErrorCategory.OperationStopped, Name));
}
}
}
}