Skip to content

Commit

Permalink
Avoid empty log file output in ADBadPassCheck.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
sawft99 authored Apr 11, 2024
1 parent 6ea330f commit 457263b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions ADBadPassCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ function BadPassCheck {
$FinalInfo
}
if (($Loops -gt 1) -or ($Loops -eq 0)) {
#Uncomment if you want to have a header to break up each section
[string]$Time = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
#Write-Host '-----------------------------------'
#Write-Host "Series Break: $Time"
#Write-Host '-----------------------------------'
if ($LogOption -eq $true) {
if ($null -ne $UsersQuery) {
#Uncomment if you want to have a header to break up each section
[string]$Time = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
'-------------------------------------' | Out-File -Append $LogLocation
"Series Break: $Time" | Out-File -Append $LogLocation
'-------------------------------------' | Out-File -Append $LogLocation
#Write-Host '-----------------------------------'
#Write-Host "Series Break: $Time"
#Write-Host '-----------------------------------'
}
if ($LogOption -eq $true) {
if ($null -ne $UsersQuery) {
#Uncomment if you want to have a header to break up each section
[string]$Time = (Get-Date).ToString('MM/dd/yyyy hh:mm:ss tt')
'-------------------------------------' | Out-File -Append $LogLocation
"Series Break: $Time" | Out-File -Append $LogLocation
'-------------------------------------' | Out-File -Append $LogLocation
}
}
}
$UsersQuery
Expand All @@ -68,7 +72,7 @@ if ($Loops -ge 1) {
Start-Sleep $SeriesDelay
}
$Check = BadPassCheck
if ($LogOption -eq $true) {
if (($LogOption -eq $true) -and ($null -ne $Check)) {
$Check | Format-Table Name,SamAccountName,LastBadPasswordAttempt | Out-File $LogLocation -Append
}
$Check | Format-Table Name,SamAccountName,LastBadPasswordAttempt
Expand All @@ -83,7 +87,7 @@ if ($Loops -ge 1) {
}
$Check = BadPassCheck
$Check | Format-Table Name,SamAccountName,LastBadPasswordAttempt
if ($LogOption -eq $true) {
if (($LogOption -eq $true) -and ($null -ne $Check)) {
$Check | Format-Table Name,SamAccountName,LastBadPasswordAttempt | Out-File $LogLocation -Append
}
$Check = $null
Expand Down

0 comments on commit 457263b

Please sign in to comment.