Skip to content

Restore-DbaDatabase -ReplaceDbNameInFile does not work #9656

Open
@MuschPu

Description

@MuschPu

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

please look at Example: 14 for command: Restore-DbaDatabase


I have used it successfully with dbatools 2.1.10 .

Restore-DbaDatabase -SqlInstance $ziel -Path "c:\install\wwn_authorization_711.bak" -DatabaseName "xxx_wwn_authorization_711xxxx" -ReplaceDbNameInFile -WithReplace -OutputScriptOnly

RESTORE DATABASE [xxx_wwn_authorization_711xxxx] FROM DISK = N'c:\install\wwn_authorization_711.bak' WITH FILE = 1, MOVE N'wwn_authorization_663' TO N'M:\MSSQL_LOVIONT\MSSQL16.LOVIONT\MSSQL\Data\wwn_authorization_663.mdf',
MOVE N'wwn_authorization_663_log' TO N'M:\MSSQL_LOVIONT\MSSQL16.LOVIONT\MSSQL\TP\wwn_authorization_663_log.ldf', NOUNLOAD, REPLACE, STATS = 10


after dbatools updated to 2.1.14

-ReplaceDbNameInFile does not work
-OutputScriptOnly does not work

after dbatools updated to the last version 2.1.30 it still does not work

e.g.
Restore-DbaDatabase -SqlInstance $ziel -Path "c:\install\wwn_authorization_711.bak" -DatabaseName "xxx_wwn_authorization_711xxxx" -ReplaceDbNameInFile -WithReplace -OutputScriptOnly
WARNING: [22:42:29][Test-DbaBackupInformation] File D:\DBA\DBMPWWE06\wwn_authorization_663.mdf already exists on exwwewvq18711\DBMPWWE06 and owned by another database, cannot restore
WARNING: [22:42:29][Test-DbaBackupInformation] File D:\DBA\DBMPWWE06\wwn_authorization_663_log.ldf already exists on exwwewvq18711\DBMPWWE06 and owned by another database, cannot restore
WARNING: [22:42:29][Restore-DbaDatabase] Database xxx_wwn_authorization_711xxxx unable to be restored, see warnings for details

Steps to Reproduce

Restore-DbaDatabase -SqlInstance $ziel -Path "c:\install\wwn_authorization_711.bak" -DatabaseName "xxx_wwn_authorization_711xxxx" -ReplaceDbNameInFile -WithReplace -OutputScriptOnly



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

**after dbatools updated to the last version 2.1.30    it still does not work** 

### Other details or mentions

_No response_

### What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

### PowerShell Host Version


Name                           Value                                                                                                                                                                                                          
----                           -----                                                                                                                                                                                                          
PSVersion                      5.1.20348.2849                                                                                                                                                                                                 
PSEdition                      Desktop                                                                                                                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                        
BuildVersion                   10.0.20348.2849                                                                                                                                                                                                
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                
WSManStackVersion              3.0                                                                                                                                                                                                            
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                            
SerializationVersion           1.1.0.1                                                                                                                                                                                                        




### SQL Server Edition and Build number

Microsoft SQL Server 2022 (RTM-CU18) (KB5050771) - 16.0.4185.3 (X64)   Feb 28 2025 18:24:49   Copyright (C) 2022 Microsoft Corporation  Standard Edition (64-bit) on Windows Server 2022 Standard 10.0 <X64> (Build 20348: ) (Hypervisor) 

### .NET Framework Version

.NET Framework 4.8.4785.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions