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

Test-DbaWindowsLogin, add property for mismatch on samaccountname #9589

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all 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
6 changes: 6 additions & 0 deletions public/Test-DbaWindowsLogin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function Test-DbaWindowsLogin {
}
Write-Message -Message "Parsing Login $adLogin." -Level Verbose
$exists = $false
$samAccountNameMismatch = $false
try {
$loginBinary = [byte[]]$winLogin.Sid
$SID = New-Object Security.Principal.SecurityIdentifier($loginBinary, 0)
Expand All @@ -196,6 +197,7 @@ function Test-DbaWindowsLogin {
if ($u.SamAccountName -ne $username) {
Write-Message -Message "SamAccountName mismatch detected for $adLogin." -Level Warning
Write-Message -Message "SamAccountName mismatch detected for $adLogin (MSSQL: $username, AD: $($u.SamAccountName))." -Level Debug
$samAccountNameMismatch = $true
}
} catch {
Write-Message -Message "AD Searcher Error for $username." -Level Warning
Expand Down Expand Up @@ -236,6 +238,7 @@ function Test-DbaWindowsLogin {
Login = $username
Type = $adType
Found = $exists
SamAccountNameMismatch = $samAccountNameMismatch
DisabledInSQLServer = $winLogin.IsDisabled
AccountNotDelegated = $additionalProps.AccountNotDelegated
AllowReversiblePasswordEncryption = $additionalProps.AllowReversiblePasswordEncryption
Expand Down Expand Up @@ -263,6 +266,7 @@ function Test-DbaWindowsLogin {
}
Write-Message -Message "Parsing Login $adLogin on $($_.Parent)." -Level Verbose
$exists = $false
$samAccountNameMismatch = $false
try {
$loginBinary = [byte[]]$winLogin.Sid
$SID = New-Object Security.Principal.SecurityIdentifier($loginBinary, 0)
Expand All @@ -282,6 +286,7 @@ function Test-DbaWindowsLogin {
if ($u.SamAccountName -ne $groupName) {
Write-Message -Message "SamAccountName mismatch detected for $adLogin." -Level Warning
Write-Message -Message "SamAccountName mismatch detected for $adLogin (MSSQL: $groupName, AD: $($u.SamAccountName))." -Level Debug
$samAccountNameMismatch = $true
}
} catch {
Write-Message -Message "AD Searcher Error for $groupName on $($_.Parent)" -Level Warning
Expand All @@ -292,6 +297,7 @@ function Test-DbaWindowsLogin {
Login = $groupName
Type = "Group"
Found = $exists
SamAccountNameMismatch = $samAccountNameMismatch
DisabledInSQLServer = $winLogin.IsDisabled
AccountNotDelegated = $null
AllowReversiblePasswordEncryption = $null
Expand Down