Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In some situations, it is necessary to use credentials for getting the Domain Controller using the DetectDC parameter. #77

Merged
merged 6 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Private/Other/Get-ServersList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function Get-ServersList {
param(
[System.Collections.IDictionary] $Definitions,
[System.Collections.IDictionary] $Target,
[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty
[System.Collections.IDictionary] $Dates,
[switch] $Quiet,
[string] $Who,
Expand Down Expand Up @@ -30,7 +31,11 @@ function Get-ServersList {
}
if ($Target.DomainControllers.Enabled) {
if (-not $Quiet) { $Logger.AddInfoRecord("Preparing servers list - domain controllers autodetection") }
[Array] $Servers = (Get-WinADDomainControllers -SkipEmpty).HostName
if($Credential) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it always true? Since you set it to Empty by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right.
I will fix this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok fixed.

[Array] $Servers = (Get-WinADDomainControllers -SkipEmpty -Credential $Credential).HostName
} else {
[Array] $Servers = (Get-WinADDomainControllers -SkipEmpty).HostName
}
$Servers
}
)
Expand Down Expand Up @@ -159,4 +164,4 @@ function Get-ServersList {
} else {
, $ExtendedInput
}
}
}
8 changes: 6 additions & 2 deletions Public/Find-Events.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ function Find-Events {
if ($EventRecordID -ne 0 -and $EventID -ne 0) {
[Array] $ExtendedInput = Get-ServersListLimited -Target $Target -RecordID $EventRecordID -Quiet:$Quiet -Who $Who -Whom $Whom -NotWho $NotWho -NotWhom $NotWhom
} else {
[Array] $ExtendedInput = Get-ServersList -Definitions $Definitions -Target $Target -Dates $Dates -Quiet:$Quiet -Who $Who -Whom $Whom -NotWho $NotWho -NotWhom $NotWhom
if ($Credential) {
[Array] $ExtendedInput = Get-ServersList -Credential $Credential -Definitions $Definitions -Target $Target -Dates $Dates -Quiet:$Quiet -Who $Who -Whom $Whom -NotWho $NotWho -NotWhom $NotWhom
} else {
[Array] $ExtendedInput = Get-ServersList -Definitions $Definitions -Target $Target -Dates $Dates -Quiet:$Quiet -Who $Who -Whom $Whom -NotWho $NotWho -NotWhom $NotWhom
}
}
if (-not $ExtendedInput) {
$Logger.AddErrorRecord("There are no logs/servers to scan. Please fix Targets and try again.")
Expand Down Expand Up @@ -190,4 +194,4 @@ $DatesRangeScriptBlock = {
}

Register-ArgumentCompleter -CommandName Find-Events -ParameterName Report -ScriptBlock $ReportScriptBlock
Register-ArgumentCompleter -CommandName Find-Events -ParameterName DatesRange -ScriptBlock $DatesRangeScriptBlock
Register-ArgumentCompleter -CommandName Find-Events -ParameterName DatesRange -ScriptBlock $DatesRangeScriptBlock