Added assembly name and root namespace to project file; updated session and vlan classes with new properties; modified module manifest to reference DLL and updated exported cmdlets; corrected property name in address class.
This commit is contained in:
98
classlib/Cmdlets/GetTagCmdlet.cs
Normal file
98
classlib/Cmdlets/GetTagCmdlet.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
namespace PS.IPAM.Cmdlets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Management.Automation;
|
||||
using PS.IPAM;
|
||||
using PS.IPAM.Helpers;
|
||||
|
||||
[Cmdlet(VerbsCommon.Get, "Tag", DefaultParameterSetName = "NoParams")]
|
||||
[OutputType(typeof(Tag))]
|
||||
public class GetTagCmdlet : PSCmdlet
|
||||
{
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "ByID")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public int? Id { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "ByAddressObject")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public Address? AddressObject { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0,
|
||||
ParameterSetName = "BySubnetObject")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public Subnetwork? SubnetObject { get; set; }
|
||||
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
try
|
||||
{
|
||||
var identifiers = new List<string> { "tags" };
|
||||
|
||||
switch (ParameterSetName)
|
||||
{
|
||||
case "ByID":
|
||||
if (Id.HasValue)
|
||||
{
|
||||
identifiers.Add(Id.Value.ToString());
|
||||
}
|
||||
break;
|
||||
case "ByAddressObject":
|
||||
if (AddressObject?.TagId > 0)
|
||||
{
|
||||
identifiers.Add(AddressObject.TagId.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "BySubnetObject":
|
||||
if (SubnetObject?.TagId > 0)
|
||||
{
|
||||
identifiers.Add(SubnetObject.TagId.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var result = RequestHelper.InvokeRequest("GET", controllers.addresses, types.Tag, null, null, identifiers.ToArray())
|
||||
.GetAwaiter().GetResult();
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
if (result is System.Collections.IEnumerable enumerable && !(result is string))
|
||||
{
|
||||
foreach (var item in enumerable)
|
||||
{
|
||||
WriteObject(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteObject(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteError(new ErrorRecord(ex, "GetTagError", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user