dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.44k stars 796 forks source link

Export-DbaServerRole - Fails on case-sensitive systems #9262

Closed danielkimberlin closed 6 months ago

danielkimberlin commented 7 months ago

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

The multi-part identifier "sp.type" could not be bound. The multi-part identifier "sp.name" could not be bound. The multi-part identifier "sPerm.permission_name" could not be bound.

Steps to Reproduce

Export-DbaServerRole -SqlInstance "REDACTED" -IncludeRoleMember -Passthru Where "REDACTED" has a case sensitive collation

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

2.1.8

Other details or mentions

The errors are due to the first SQL query stored in the $roleSQL variable. The text of the query references columns from table aliases that have mismatched case. ie. FROM sys.server_permissions SPerm then referencing a column in the alias as sPerm.permission_name as Permission.

There are a couple of these and they seem to be isolated to this first query.

What PowerShell host was used when producing this error

VS Code (terminal)

PowerShell Host Version

Name Value


PSVersion 5.1.22621.2506
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.22621.2506
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 2019 (RTM-CU22-GDR) (KB5029378) - 15.0.4326.1 (X64) Aug 18 2023 14:05:15 Copyright (C) 2019 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2022 Standard 10.0 (Build 20348: ) (Hypervisor)

.NET Framework Version

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.09032
Full 4.8.09032 Client 4.0.0.0

andreasjordan commented 6 months ago

Thanks for reporting this and the analysis. I'll open a PR to provide a fix soon.