DSInternals/Src/DSInternals.PowerShell/Commands/Datastore/GetADDBSchemaAttributeCommand.cs
2017-03-11 18:14:41 +01:00

52 lines
1.8 KiB
C#

namespace DSInternals.PowerShell.Commands
{
using System.Management.Automation;
using AutoMapper;
[Cmdlet(VerbsCommon.Get, "ADDBSchemaAttribute")]
[OutputType(typeof(DSInternals.PowerShell.SchemaAttribute))]
public class GetADDBSchemaAttributeCommand : ADDBCommandBase
{
[Parameter(
Position = 0,
HelpMessage = "TODO",
ValueFromPipeline = true
)]
[Alias("LdapDisplayName,AttributeName,AttrName,Attr")]
[ValidateNotNullOrEmpty]
public string[] Name
{
get;
set;
}
protected override void BeginProcessing()
{
base.BeginProcessing();
Mapper.Initialize(cfg => cfg.CreateMap<DSInternals.DataStore.SchemaAttribute, DSInternals.PowerShell.SchemaAttribute>());
}
protected override void ProcessRecord()
{
if (this.Name == null)
{
// No attribute list provided, so return all attributes.
var attributes = this.DirectoryContext.Schema.FindAllAttributes();
foreach (var attribute in attributes)
{
var attributeTransfer = Mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
this.WriteObject(attributeTransfer);
}
}
else
{
// Return only requested attributes
foreach(string attributeName in this.Name)
{
var attribute = this.DirectoryContext.Schema.FindAttribute(attributeName);
var attributeTransfer = Mapper.Map<DSInternals.PowerShell.SchemaAttribute>(attribute);
this.WriteObject(attributeTransfer);
}
}
}
}
}