Skip to content

Commit

Permalink
Get-DbaPermission - fix returning Null in field 'Securable' (#9171)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncletimmy3 authored Dec 4, 2023
1 parent 6872543 commit 663f450
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions public/Get-DbaPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ']'
Expand Down Expand Up @@ -326,4 +329,4 @@ function Get-DbaPermission {
}
}
}
}
}

0 comments on commit 663f450

Please sign in to comment.