Connect-DbaInstance 2.9.1 fails to use supplied Windows SqlCredential when running as LocalSystem; works in 2.8.3

Đang mở
#10,860 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
powershell
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start by tracing how Connect-DbaInstance handles -SqlCredential and determines IsLocalHost when running under LocalSystem; the issue does not name the relevant files or tests. Compare the behavior with dbatools 2.8.3 and 2.9.1, then reproduce the scheduled task case using the supplied steps. Done means the supplied credential connects successfully under LocalSystem in 2.9.1 while interactive behavior remains intact.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bugs life triage required
Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

VERBOSE: [Connect-DbaInstance] Starting loop for 'server.domain.com':

ComputerName = 'server.domain.com',

InstanceName = 'MSSQLSERVER',

IsLocalHost = 'False',

Type = 'Default'

VERBOSE: [Connect-DbaInstance] String is passed in, will build server object from instance object and other parameters, do some checks and then return the server object

VERBOSE: [Connect-DbaInstance] authentication method is 'local ad'

TerminatingError(): "Error connecting to [SERVER]: Login failed for user 'DOMAIN\SERVER$'."

WARNING: [Export-DbaCredential] Failure | Login failed for user 'DOMAIN\SERVER$'.

TerminatingError(): "System error."

The form requests the output of $Error[0] | Select-Object *. I attempted to capture this immediately after reproducing the failure under LocalSystem, including writing $Error[0], $Error[0].Exception, and the complete $Error collection directly to files. All were empty. The error above is therefore copied from the PowerShell transcript produced during the failing scheduled-task execution.

This behavior is specific to dbatools 2.9.1 when executed under NT AUTHORITY\SYSTEM. The identical connection succeeds with dbatools 2.8.3 under the same scheduled task, and dbatools 2.9.1 also succeeds when run interactively as a domain user.

Steps to Reproduce

Start-Transcript -Path c:\test\test.log

#Required Variables

$SQLInstance = "servername.domain.net"

$CredentialName = "domain\account"

Import-Module dbatools

#To Show the identity the script is running under in the transcript log

Write-Host "Script Running Identity:"
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name

#Below is a custom internal module to retrieve the password from our safe
#Validated on my ends as running successful

$SQLCreds = Get-PasswordForSQLCreds -PSCredential -FullyQualified

#Validates for the transcript log the credentials are as expected

Write-Host "Gathered Credential"
Write-Host "Credential type: $($SQLCreds.GetType().FullName)"

Write-Host "Credential user: $($SQLCreds.UserName)"

#Added the -Verbose as it seems to be the only way to see the error when running via a scheduled
#Task, this will show in the transcript log

$SQLServer = Connect-DbaInstance -SqlInstance $SQLInstance -SqlCredential $SQLCreds -ErrorAction Stop -Verbose

#This was put in place to just return something for the transcript log, it's just a blank line when the
#issue occurs.

$SQLServer

Write-Host "Connected to: $($SQLServer.Name)"

#If the above actually works, this would be expected to run next

$CredentialScript = Export-DbaCredential -SqlInstance $SQLServer -Identity $CredentialName -Passthru

#Displays for the transcript, this was only added for troubleshooting
Write-Host $CredentialScript

Stop-Transcript

Please confirm that you are running the most recent version of dbatools

Capture from transcript log due to this running as a scheduled task:

Major Minor Build Revision


2 9 1 -1

Other details or mentions

The actual script has been in place for a long time without issues. It was the introduction of updating to dbatools 2.9.1 that the issue arose. Note, in the reproduction steps, you must run the script in a scheduled task under the LocalSystem credentials. It runs successfully interactively. Also, to prove it works under 2.8.3 (my most recent installed version prior to 2.9.1), I did "Import-Module dbatools -RequiredVersion 2.8.3" in the supplied script. When you are loaded 2.8.3 and run from a scheduled task, it runs as it should. Also note in the error message supplied, the script is running from the same server hosting the SQL instance. Notice IsLocalHost = 'False', that is incorrect, it should be True. As an alternate test, supply just the short server name, it will do True, but, authentication will still fail with a different error. Again, either way, 2.8.3 works.

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name Value


PSVersion 7.6.9

PSEdition Core

GitCommitId 7.6.9

OS Microsoft Windows 10.0.17763

Platform Win32NT

PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}

PSRemotingProtocolVersion 2.4

SerializationVersion 1.1.0.1

WSManStackVersion 3.0

SQL Server Edition and Build number

Microsoft SQL Server 2019 (RTM-CU32-GDR) (KB5128494) - 15.0.4500.2 (X64) Sep 26 2026 20:15:06 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: ) (Hypervisor)

.NET Framework Version

.NET 10.0.14

or...

PSChildName Version


v2.0.50727 2.0.50727.4927

v3.0 3.0.30729.4926

Windows Communication Foundation 3.0.4506.4926

Windows Presentation Foundation 3.0.6920.4902

v3.5 3.5.30729.4926

Client 4.8.03761

Full 4.8.03761

Client 4.0.0.0

Ngôn ngữ chính
PowerShell
Star
2.9k
Fork
869
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dataplat/dbatools

Tất cả issue của dataplat/dbatools

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.