Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Get-DbaFile.ps1 #9202

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion public/Get-DbaFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,14 @@ function Get-DbaFile {
foreach ($type in $FileTypeComparison) {
if ($row.filename.ToLowerInvariant().EndsWith(".$type")) {
$fullpath = $row.fullpath.Replace("\", $separator)

# Replacing all instances of '\\' with single backslashes '\', and maintain the leading SMB share path represented by the initial '\\'.
$is_smb_share_path = $fullpath.SubString(0, 2) -eq "\\"
$fullpath = $fullpath.Replace("\\", "\")
if ($is_smb_share_path) {
$fullpath = $fullpath -replace "^\\", "\\"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to remember why even try to change the path separator from what SQL returns 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In SQL Server, you can create a database like this:


CREATE DATABASE [test]
ON PRIMARY
(
    NAME = N'test',
    FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL16.MSSQLSERVER\\MSSQL\\DATA\\test.mdf',
    SIZE = 8192KB,
    FILEGROWTH = 65536KB
)
LOG ON
(
    NAME = N'test_log',
    FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL16.MSSQLSERVER\\MSSQL\\DATA\\test_log.ldf',
    SIZE = 8192KB,
    FILEGROWTH = 65536KB
);

After creating the database, if you query the sys.database_files DMV, you will get a physical_name like C:\\Program Files\\Microsoft SQL Server\\MSSQL16.MSSQLSERVER\\MSSQL\\DATA\\test.mdf. Also, if there are flaws in your script when moving database files, you could encounter the same issues. It seems that the replace operation is intended to address these issues.

$fullpath = $fullpath.Replace("//", "/")
[PSCustomObject]@{
ComputerName = $server.ComputerName
Expand Down Expand Up @@ -220,4 +227,4 @@ function Get-DbaFile {
}
}
}
}
}
Loading