namespace PS.IPAM.Cmdlets; using System; using System.Collections.Generic; using System.Management.Automation; using PS.IPAM; using PS.IPAM.Helpers; [Cmdlet("Assign", "Tag")] public class AssignTagCmdlet : PSCmdlet { [Parameter( Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, Position = 0)] [ValidateNotNullOrEmpty] public Address? AddressObject { get; set; } [Parameter( Mandatory = true, Position = 1)] [ValidateNotNullOrEmpty] public Tag? Tag { get; set; } protected override void ProcessRecord() { try { var identifiers = new List { AddressObject!.Id.ToString() }; var body = new Dictionary { { "tag", Tag!.Id } }; RequestHelper.InvokeRequest("PATCH", controllers.addresses, null, null, body, identifiers.ToArray()) .GetAwaiter().GetResult(); } catch (Exception ex) { WriteError(new ErrorRecord(ex, "AssignTagError", ErrorCategory.InvalidOperation, null)); } } }