diff --git a/Private/Other/Get-ServersList.ps1 b/Private/Other/Get-ServersList.ps1 index 784bba8..4cab7eb 100644 --- a/Private/Other/Get-ServersList.ps1 +++ b/Private/Other/Get-ServersList.ps1 @@ -3,6 +3,7 @@ function Get-ServersList { param( [System.Collections.IDictionary] $Definitions, [System.Collections.IDictionary] $Target, + [System.Management.Automation.Credential()]$Credential, [System.Collections.IDictionary] $Dates, [switch] $Quiet, [string] $Who, @@ -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) { + [Array] $Servers = (Get-WinADDomainControllers -SkipEmpty -Credential $Credential).HostName + } else { + [Array] $Servers = (Get-WinADDomainControllers -SkipEmpty).HostName + } $Servers } ) @@ -159,4 +164,4 @@ function Get-ServersList { } else { , $ExtendedInput } -} \ No newline at end of file +} diff --git a/Public/Find-Events.ps1 b/Public/Find-Events.ps1 index b44599c..818dfd3 100644 --- a/Public/Find-Events.ps1 +++ b/Public/Find-Events.ps1 @@ -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.") @@ -190,4 +194,4 @@ $DatesRangeScriptBlock = { } Register-ArgumentCompleter -CommandName Find-Events -ParameterName Report -ScriptBlock $ReportScriptBlock -Register-ArgumentCompleter -CommandName Find-Events -ParameterName DatesRange -ScriptBlock $DatesRangeScriptBlock \ No newline at end of file +Register-ArgumentCompleter -CommandName Find-Events -ParameterName DatesRange -ScriptBlock $DatesRangeScriptBlock