using System; using System.Management.Automation; using PSProxmox.Models; using PSProxmox.Templates; namespace PSProxmox.Cmdlets { /// /// Removes a virtual machine template. /// The Remove-ProxmoxVMTemplate cmdlet removes a virtual machine template. /// /// Remove a template /// Remove-ProxmoxVMTemplate -Name "Ubuntu-Template" /// /// /// Remove a template using pipeline input /// Get-ProxmoxVMTemplate -Name "Ubuntu-Template" | Remove-ProxmoxVMTemplate /// /// [Cmdlet(VerbsCommon.Remove, "ProxmoxVMTemplate", SupportsShouldProcess = true)] public class RemoveProxmoxVMTemplateCmdlet : PSCmdlet { /// /// The name of the template to remove. /// [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)] public string Name { get; set; } /// /// Processes the cmdlet. /// protected override void ProcessRecord() { try { // Confirm removal if (!ShouldProcess($"Template {Name}", "Remove")) { return; } // Remove the template WriteVerbose($"Removing template {Name}"); TemplateManager.RemoveTemplate(Name); WriteVerbose($"Template {Name} removed"); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "RemoveProxmoxVMTemplateError", ErrorCategory.InvalidOperation, Name)); } } } }