-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
[System.IO.Path]::GetExtension() does not accept objects as input in PS6 #5070
Comments
Thanks for the report, we'll take a look asap (but possible may be a bit away, sorry) |
nope, my attempts failed. will need stuart's assistance with this one. |
Thanks for your efforts! |
So this is an interesting one ... @Stuart-Moore SQL Server 2017 on Linux (Container) using this docker-compose file:
Now note the context of the error:
Now from Read-DbaBackupHeader -SqlInstance 'localhost,1417' -SqlCredential $containerCred -Path '/var/opt/mssql/backups/nw.bak' But $FileDetails = Read-DbaBackupHeader -SqlInstance $server -Path $Files -AzureCredential $AzureCredential Debugger for this one will not show the error occurring. So I go back and just added a verbose message for line 105:
Now the problem is this works on PS Core: [object]$p = '/var/opt/mssql/backups/'
$p.GetType()
[System.Io.Path]::GetExtension($p).Length
[System.Io.Path]::GetExtension($p).Length -gt 0 Ok I think our only option is to go with Interesting part to deal with is the difference in how that path object is passed in because the warning will vary on whether it outputs the true value in the warning message:
|
Before submitting a bug report:
powershell -NoProfile
)Steps to Reproduce
Explanation
Forgive me if I get any of the terminology wrong.
The root error is in how Get-DbaBackupInformation passes file names to Read-DbaBackupHeader, so I would expect this error to pop up in other functions as well.
Restore-DbaDatabase calls Get-DbaBackupInformation, which collects metadata of all backup files in a folder by putting all the file names in an array. These file names should be passed as strings. However, sometimes they are passed as objects. Then the array is passed to Read-DbaBackupHeader which tries to determine whether each element in the array has an extension or not: [System.IO.Path]::GetExtension($file). Apparently in PS5.1 when the array would consist of objects these were implicitly converted to strings by this function. This was basically always wrong to begin with, because the result would be "@{file.extension}" instead of "file.extension". In PS6 GetExtension apparently does not accept objects at all anymore.
This behavior can be observed by running the following code in PS5.1 and PS6 and comparing the output:
Proposed Solution
In lines 227, 231, 258, 259 and 260 of Get-DbaBackupInformation change the code from
to
This might not be complete, but it would solve it for my scenario.
Environmental data
The text was updated successfully, but these errors were encountered: