Skip to content

Commit

Permalink
Connect-DbaInstance, change username format only when joined to AD
Browse files Browse the repository at this point in the history
  • Loading branch information
niphlod committed Feb 25, 2025
1 parent bb33a85 commit 4dde0cc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions public/Connect-DbaInstance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,18 @@ function Connect-DbaInstance {
$authType = 'local '
}
if ($SqlCredential) {
# support both ad\username and username@ad
# username@ad works only for domain joined
# so we stick to what we get and allow ad\username
# as well, that works on local and workgroup
$username = ($SqlCredential.UserName).TrimStart("\")
# support both ad\username and username@ad
# username@ad works only for domain joined and workgroup
# nobody remembers why, but username@ad is preferred
# so we switch ad\username to username@ad only doing a raw guess
# when USERDOMAIN -ne COMPUTERNAME, we're probably joined to ad
if ($env:USERDOMAIN -ne $env:COMPUTERNAME) {
if ($username -like "*\*") {
$domain, $login = $username.Split("\")
$username = "$login@$domain"
}
}
if ($username -like '*@*' -or $username -like '*\*') {
$authType += 'ad'
} else {
Expand Down

0 comments on commit 4dde0cc

Please sign in to comment.