Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
PSMessageDetails :
Exception : System.Exception: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database snapshot creation. Missing the file
"StackOverflow2010".
---> System.Management.Automation.MethodInvocationException: Exception calling "Query" with "1" argument(s): "An exception occurred while executing a Transact-SQL
statement or batch.All files must be specified for database snapshot creation. Missing the file "StackOverflow2010"."
---> System.Management.Automation.RuntimeException: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database
snapshot creation. Missing the file "StackOverflow2010".
---> System.Management.Automation.RuntimeException: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database
snapshot creation. Missing the file "StackOverflow2010".
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
/root/parts/powershell/build/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs:line 1791
at (Closure, FunctionContext)
at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary2 functionsToDefine, List1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo,
Object[] args) in /root/parts/powershell/build/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs:line 1211
at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object
scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List1 variablesToDefine, Dictionary2 functionsToDefine, Object[] args)
in /root/parts/powershell/build/src/System.Management.Automation/engine/lang/scriptblock.cs:line 980
at System.Management.Automation.PSScriptMethod.InvokeScript(String methodName, ScriptBlock script, Object this, Object[] arguments) in
/root/parts/powershell/build/src/System.Management.Automation/engine/MshMemberInfo.cs:line 2411
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
/root/parts/powershell/build/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs:line 1791
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/CallInstruction.Generated.cs:line 504
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs:line 389
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs:line 355
--- End of inner exception stack trace ---
TargetObject : [StackOverflow2010_20250821_223343]
CategoryInfo : NotSpecified: ([StackOverflow2010_20250821_223343]:PSObject) [Write-Error], Exception
FullyQualifiedErrorId : dbatools_New-DbaDbSnapshot,Stop-Function
ErrorDetails : An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database snapshot creation. Missing the file "StackOverflow2010".
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Stop-Function, : line 98467
at New-DbaDbSnapshot, : line 60170
at , : line 1
PipelineIterationInfo : {0, 1}
Steps to Reproduce
This is a copy and paste of #9786 with only the last few lines changed. It spins up an Availability Group with two nodes.
I'm using this copy of StackOverflow2010. Extract it to a useful location. This script has a docker cp '/YourDownloads/StackOverflow2010/' 2025box1:/var/opt/mssql/data/ line that you will need to change.
Set up environment
docker stop 2025box1
docker rm 2025box1
docker stop 2025box2
docker rm 2025box2
docker pull mcr.microsoft.com/mssql/server:2025-latest
docker network create localnet
docker run -e "ACCEPT_EULA=Y" `
-e "MSSQL_ENABLE_HADR=1" `
-e "MSSQL_AGENT_ENABLED=true" `
-e "MSSQL_SA_PASSWORD=ILuvDbat00ls" `
-p 1431:1433 `
--volume shared:/shared:z `
--name 2025box1 --hostname 2025box1 `
--network localnet `
-d mcr.microsoft.com/mssql/server:2025-latest
docker run -e "ACCEPT_EULA=Y" `
-e "MSSQL_ENABLE_HADR=1" `
-e "MSSQL_AGENT_ENABLED=true" `
-e "MSSQL_SA_PASSWORD=ILuvDbat00ls" `
-p 1439:1433 `
--volume shared:/shared:z `
--name 2025box2 --hostname 2025box2 `
--network localnet `
-d mcr.microsoft.com/mssql/server:2025-latest
docker start 2025box1
docker start 2025box2
docker cp '/YourDownloads/StackOverflow2010/' 2025box1:/var/opt/mssql/data/
$password = ConvertTo-SecureString "ILuvDbat00ls" -AsPlainText
$cred = [PsCredential]::New("sa", $password)
$primary = Connect-DbaInstance -SqlInstance localhost:1431 -SqlCredential $cred -TrustServerCertificate
$secondary = Connect-DbaInstance -SqlInstance localhost:1439 -SqlCredential $cred -TrustServerCertificate
# I do not know why I cannot get this to work in dbatools, only T-SQL works for me.
$AttachDb = @"
CREATE DATABASE StackOverflow2010
ON (FILENAME = '/var/opt/mssql/data/StackOverflow2010.mdf')
LOG ON (FILENAME = '/var/opt/mssql/data/StackOverflow2010_log.ldf')
FOR ATTACH;
"@
Invoke-DbaQuery -SqlInstance $primary -Query $AttachDb
Set-DbaDbRecoveryModel -SqlInstance $primary -Database StackOverflow2010 -RecoveryModel Full -Confirm:$false
New-DbaDbMasterKey -SqlInstance $primary, $secondary -Credential $cred -Confirm:$false
New-DbaDbCertificate -SqlInstance $primary -Name mirror -Subject mirror -Confirm:$false
$cert = (Backup-DbaDbCertificate -SqlInstance $primary -Suffix $null -Certificate mirror -Path '/shared' -EncryptionPassword $password -Confirm:$false).Path
Restore-DbaDbCertificate -SqlInstance $secondary -Path $cert -DecryptionPassword $password -Confirm:$false
New-DbaEndpoint -SqlInstance $primary, $secondary -Name mirror -Certificate mirror -Port 5022
Start-DbaEndpoint -SqlInstance $primary, $secondary -EndPoint mirror
Backup-DbaDatabase -SqlInstance $primary -Database StackOverflow2010
Backup-DbaDatabase -SqlInstance $primary -Database StackOverflow2010 -Type Log
$params = @{
Primary = $primary
Secondary = $secondary
Name = "test-ag"
Database = "StackOverflow2010"
ClusterType = "None"
SeedingMode = "Automatic"
FailoverMode = "Manual"
Confirm = $false
}
New-DbaAvailabilityGroup @params
The Problem
# Does absolutely nothing
New-DbaDbSnapshot -SqlInstance $secondary -Database StackOverflow2010
# Do this and you at least get an error
$secondary = Connect-DbaInstance -SqlInstance localhost:1439 -SqlCredential $cred -TrustServerCertificate
New-DbaDbSnapshot -SqlInstance $secondary -Database StackOverflow2010
See the start of this report for the error.
Please confirm that you are running the most recent version of dbatools
Major Minor Build Revision
2 5 5 -1
Other details or mentions
-Verbose gives no extra useful information.
Making the secondary readable, which I think the below code does correctly, changes nothing
Get-DbaAgReplica -SqlInstance $primary -Replica 2025box2 | Set-DbaAgReplica -ReadonlyRoutingConnectionUrl 'TCP://localhost:9999'
Get-DbaAgReplica -SqlInstance $primary -Replica 2025box1 | Set-DbaAgReplica -ReadonlyRoutingList 2025box2 -ConnectionModeInSecondaryRole AllowReadIntentConnectionsOnly
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
Name Value
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Ubuntu 24.04.2 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
SQL Server Edition and Build number
You can see the Docker container that I'm using.
I repeated this test on 2022 Developer Edition and found the same results.
I also tried with 2025 Standard Developer Edition and found the same result. I therefore conclude that #9632 is unrelated.
.NET Framework Version
.NET 9.0.7
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
PSMessageDetails :
Exception : System.Exception: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database snapshot creation. Missing the file
"StackOverflow2010".
---> System.Management.Automation.MethodInvocationException: Exception calling "Query" with "1" argument(s): "An exception occurred while executing a Transact-SQL
statement or batch.All files must be specified for database snapshot creation. Missing the file "StackOverflow2010"."
---> System.Management.Automation.RuntimeException: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database
snapshot creation. Missing the file "StackOverflow2010".
---> System.Management.Automation.RuntimeException: An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database
snapshot creation. Missing the file "StackOverflow2010".
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
/root/parts/powershell/build/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs:line 1791
at (Closure, FunctionContext)
at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope, Dictionary
2 functionsToDefine, List1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo,Object[] args) in /root/parts/powershell/build/src/System.Management.Automation/engine/runtime/CompiledScriptBlock.cs:line 1211
at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object
scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List
1 variablesToDefine, Dictionary2 functionsToDefine, Object[] args)in /root/parts/powershell/build/src/System.Management.Automation/engine/lang/scriptblock.cs:line 980
at System.Management.Automation.PSScriptMethod.InvokeScript(String methodName, ScriptBlock script, Object this, Object[] arguments) in
/root/parts/powershell/build/src/System.Management.Automation/engine/MshMemberInfo.cs:line 2411
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) in
/root/parts/powershell/build/src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs:line 1791
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/CallInstruction.Generated.cs:line 504
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs:line 389
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in
/root/parts/powershell/build/src/System.Management.Automation/engine/interpreter/ControlFlowInstructions.cs:line 355
--- End of inner exception stack trace ---
TargetObject : [StackOverflow2010_20250821_223343]
CategoryInfo : NotSpecified: ([StackOverflow2010_20250821_223343]:PSObject) [Write-Error], Exception
FullyQualifiedErrorId : dbatools_New-DbaDbSnapshot,Stop-Function
ErrorDetails : An exception occurred while executing a Transact-SQL statement or batch.All files must be specified for database snapshot creation. Missing the file "StackOverflow2010".
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Stop-Function, : line 98467
at New-DbaDbSnapshot, : line 60170
at , : line 1
PipelineIterationInfo : {0, 1}
Steps to Reproduce
This is a copy and paste of #9786 with only the last few lines changed. It spins up an Availability Group with two nodes.
I'm using this copy of StackOverflow2010. Extract it to a useful location. This script has a
docker cp '/YourDownloads/StackOverflow2010/' 2025box1:/var/opt/mssql/data/line that you will need to change.Set up environment
The Problem
See the start of this report for the error.
Please confirm that you are running the most recent version of dbatools
Major Minor Build Revision
2 5 5 -1
Other details or mentions
-Verbosegives no extra useful information.Making the secondary readable, which I think the below code does correctly, changes nothing
What PowerShell host was used when producing this error
PowerShell Core (pwsh.exe)
PowerShell Host Version
Name Value
PSVersion 7.5.2
PSEdition Core
GitCommitId 7.5.2
OS Ubuntu 24.04.2 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
SQL Server Edition and Build number
You can see the Docker container that I'm using.
I repeated this test on 2022 Developer Edition and found the same results.
I also tried with 2025 Standard Developer Edition and found the same result. I therefore conclude that #9632 is unrelated.
.NET Framework Version
.NET 9.0.7