Skip to content

Commit

Permalink
add Credential parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
PoshAJ authored and PoshAJ committed Sep 6, 2024
1 parent 9fbaaca commit d6ef8a1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/PSADTree/PSADTreeCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public abstract class PSADTreeCmdletBase : PSCmdlet, IDisposable
| WildcardOptions.CultureInvariant
| WildcardOptions.IgnoreCase;


[Parameter(
Position = 0,
Mandatory = true,
Expand All @@ -44,6 +43,10 @@ public abstract class PSADTreeCmdletBase : PSCmdlet, IDisposable
[Parameter]
public string? Server { get; set; }

[Parameter(ValueFromPipelineByPropertyName = true)]
[Credential]
public PSCredential? Credential { get; set; }

[Parameter(ParameterSetName = DepthParameterSet)]
[ValidateRange(0, int.MaxValue)]
public int Depth { get; set; } = 3;
Expand Down Expand Up @@ -75,6 +78,16 @@ protected override void BeginProcessing()
return;
}

if (Credential is not null)
{
_context = new PrincipalContext(
ContextType.Domain,
Server,
Credential.UserName,
Credential.GetNetworkCredential().Password);
return;
}

_context = new PrincipalContext(ContextType.Domain, Server);
}
catch (Exception exception)
Expand Down

0 comments on commit d6ef8a1

Please sign in to comment.