Connect-DbaInstance 2.9.1 fails to use supplied Windows SqlCredential when running as LocalSystem; works in 2.8.3
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- PowerShell
- Estrellas
- 2.9k
- Forks
- 869
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 38
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dataplat/dbatools
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 2 días
-
bugs life triage required
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 2 días
-
Invoke-DbaDbPiiScan - Fix broken PII patterns, add Nordic known names, and proposals for metadata-only scan and native classificationPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 2 días
-
bugs life Chrissy needed
Dificultad 3/5 Medio día Aptitud para principiantes 38/100
Los mantenedores suelen responder en 2 días
-
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 2 días
Todos los issues de dataplat/dbatools
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
lidofinance/validator-ejector#228 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
desktop: app-version.v1 in drafts.sqlite is never refreshed — reports 1.19.4 while running 2.3.2Abiertoarea/desktop platform/windows type/feature version/v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
anomalyco/opencode#66079 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
ai-driven-qa bug claude Minor
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
linagora/cozy-stack#5374 ·
Los mantenedores suelen responder en 1 día
-
`gitlab_importer_v2` pipeline failing due to malformed YAML filePosiblemente ocupada @Gowri213 la tomó hoy. Abiertobug Pipeline: Failure Priority: high
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
aboutcode-org/vulnerablecode#2523 · 1 comentario ·
Los mantenedores suelen responder en 5 días