From 663f450b6fe07423e646ec375a2371e69aec4bca Mon Sep 17 00:00:00 2001 From: uncletimmy3 <34276679+uncletimmy3@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:13:18 +0500 Subject: [PATCH] Get-DbaPermission - fix returning Null in field 'Securable' (#9171) --- public/Get-DbaPermission.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/public/Get-DbaPermission.ps1 b/public/Get-DbaPermission.ps1 index aa49620271..e4ca773bdb 100644 --- a/public/Get-DbaPermission.ps1 +++ b/public/Get-DbaPermission.ps1 @@ -97,10 +97,13 @@ function Get-DbaPermission { , [PermState] = state_desc , [PermissionName] = permission_name , [SecurableType] = COALESCE(o.type_desc,sp.class_desc) - , [Securable] = CASE WHEN class = 100 THEN @@SERVERNAME - WHEN class = 105 THEN OBJECT_NAME(major_id) - ELSE OBJECT_NAME(major_id) - END + , [Securable] = CASE + WHEN class = 100 THEN @@SERVERNAME + WHEN class = 101 THEN SUSER_NAME(major_id) + WHEN class = 105 THEN (SELECT TOP (1) name FROM sys.endpoints WHERE endpoint_id = major_id) + WHEN class = 108 THEN (SELECT TOP (1) ag.name FROM sys.availability_replicas ar JOIN sys.availability_groups ag ON ar.group_id = ag.group_id WHERE ar.replica_metadata_id = major_id) + ELSE CONVERT(NVARCHAR, major_id) + END , [Grantee] = SUSER_NAME(grantee_principal_id) , [GranteeType] = pr.type_desc , [revokeStatement] = 'REVOKE ' + permission_name + ' ' + COALESCE(OBJECT_NAME(major_id),'') + ' FROM [' + SUSER_NAME(grantee_principal_id) + ']' @@ -326,4 +329,4 @@ function Get-DbaPermission { } } } -} \ No newline at end of file +}