DSInternals/Src/DSInternals.PowerShell/Commands/Misc/GetSamPasswordPolicyCommand.cs
2016-11-15 00:31:27 +01:00

50 lines
1.5 KiB
C#

using DSInternals.Common.Interop;
using DSInternals.SAM.Interop;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;
namespace DSInternals.PowerShell.Commands
{
[Cmdlet(VerbsCommon.Get, "SamPasswordPolicy")]
[OutputType(typeof(SamDomainPasswordInformation))]
public class GetSamPasswordPolicyCommand : SamCommandBase
{
#region Parameters
[Parameter(
HelpMessage = @"Specify AD domain.",
Mandatory = true
)]
[ValidateNotNullOrEmpty]
public string Domain
{
get;
set;
}
#endregion Parameters
#region Cmdlet Overrides
protected override void ProcessRecord()
{
this.WriteVerbose(string.Format("Opening domain {0}.", this.Domain));
if (this.Domain.Contains("."))
{
// This is not a hard check, because dots are actually allowed in NetBIOS names, although not recommended.
// TODO: Extract as a resource
this.WriteWarning("The domain name supplied appears to be a DNS name instead of NetBIOS name.");
}
using(var samDomain = this.SamServer.OpenDomain(this.Domain, SamDomainAccessMask.ReadPasswordParameters))
{
var policy = samDomain.GetPasswordPolicy();
this.WriteObject(policy);
}
}
#endregion Cmdlet Overrides
}
}