using System;
using System.Management.Automation;
using PSProxmox.Session;
namespace PSProxmox.Cmdlets
{
///
/// Disconnects from a Proxmox VE server.
/// The Disconnect-ProxmoxServer cmdlet terminates a connection to a Proxmox VE server.
///
/// Disconnect from a Proxmox VE server
/// Disconnect-ProxmoxServer -Connection $connection
///
///
[Cmdlet(VerbsCommunications.Disconnect, "ProxmoxServer")]
public class DisconnectProxmoxServerCmdlet : PSCmdlet
{
///
/// The connection to disconnect from.
///
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public ProxmoxConnection Connection { get; set; }
///
/// Processes the cmdlet.
///
protected override void ProcessRecord()
{
try
{
if (Connection == null)
{
throw new PSArgumentNullException(nameof(Connection));
}
ProxmoxSession.Logout(Connection, this);
WriteVerbose($"Disconnected from {Connection.Server}");
}
catch (Exception ex)
{
WriteError(new ErrorRecord(ex, "DisconnectProxmoxServerError", ErrorCategory.ConnectionError, Connection));
}
}
}
}