DSInternals/Src/DSInternals.PowerShell/Commands/Base/ADReplCommandBase.cs
Michael Grafnetter 85b48b32df - Added the Add-ADReplNgcKey cmdlet
- Added the UserPrincipalName parameter to Get-ADReplAccount cmdlet
- Improved DRS_MSG_GETCHGREQ_V8 delete
- Fixed Set-ADDBBootKey cmdlet output type
- Fixed some formatting inconsistencies
2019-08-24 23:07:57 +02:00

77 lines
1.8 KiB
C#

using System;
using System.Management.Automation;
using System.Net;
using DSInternals.Replication;
namespace DSInternals.PowerShell.Commands
{
public abstract class ADReplCommandBase : PSCmdlet, IDisposable
{
#region Parameters
[Parameter(Mandatory = true)]
[ValidateNotNullOrEmpty]
[Alias("Host", "DomainController", "DC")]
public string Server
{
get;
set;
}
[Parameter(Mandatory = false)]
[ValidateNotNull]
public PSCredential Credential
{
get;
set;
}
[Parameter(Mandatory = false)]
[ValidateNotNull]
[Alias("Proto", "RPCProtocol", "NCACN")]
public RpcProtocol Protocol
{
get;
set;
}
#endregion Parameters
protected DirectoryReplicationClient ReplicationClient
{
get;
private set;
}
#region Cmdlet Overrides
protected override void BeginProcessing()
{
NetworkCredential netCredential = null;
if(this.Credential != null)
{
// Convert PSCredential to NetworkCredential
netCredential = this.Credential.GetNetworkCredential();
}
this.ReplicationClient = new DirectoryReplicationClient(this.Server, this.Protocol, netCredential);
}
#endregion Cmdlet Overrides
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing && this.ReplicationClient != null)
{
this.ReplicationClient.Dispose();
this.ReplicationClient = null;
}
}
}
}