49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
namespace PS.IPAM.Cmdlets;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Management.Automation;
|
|
using PS.IPAM.Helpers;
|
|
|
|
/// <summary>
|
|
/// Retrieves L2 domain information from phpIPAM.
|
|
/// </summary>
|
|
[Cmdlet(VerbsCommon.Get, "L2Domain", DefaultParameterSetName = "ByID")]
|
|
[OutputType(typeof(Domain))]
|
|
public class GetL2DomainCmdlet : BaseCmdlet
|
|
{
|
|
[Parameter(
|
|
Mandatory = false,
|
|
ValueFromPipeline = true,
|
|
ValueFromPipelineByPropertyName = true,
|
|
Position = 0,
|
|
ParameterSetName = "ByID",
|
|
HelpMessage = "The L2 domain ID.")]
|
|
[ValidateNotNullOrEmpty]
|
|
public int? Id { get; set; }
|
|
|
|
protected override void ProcessRecord()
|
|
{
|
|
try
|
|
{
|
|
var identifiers = new List<string>();
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
identifiers.Add(Id.Value.ToString());
|
|
}
|
|
|
|
var result = RequestHelper.InvokeRequest(
|
|
"GET", ApiController.L2Domains, ModelType.Domain, null, null,
|
|
identifiers.Count > 0 ? identifiers.ToArray() : null
|
|
).GetAwaiter().GetResult();
|
|
|
|
WriteResult(result);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
WriteError(new ErrorRecord(ex, "GetL2DomainError", ErrorCategory.InvalidOperation, null));
|
|
}
|
|
}
|
|
}
|