Skip to content

Commit 355ce02

Browse files
author
Shawn Tunney
committed
Export permissions for ENDPOINTS
1 parent 188d389 commit 355ce02

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

functions/Export-DbaLogin.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,29 @@ function Export-DbaLogin {
313313
$credentialName = $credential.Name
314314
$outsql += "PRINT '$userName is associated with the $credentialName credential'"
315315
}
316+
317+
# Endpoint permissions
318+
foreach ($endpoint in $server.endpoints) {
319+
$perms = $endpoint.EnumObjectPermissions($userName)
320+
321+
foreach ($perm in $perms) {
322+
$permState = $perm.permissionstate
323+
$permType = $perm.PermissionType
324+
$grantor = $perm.grantor
325+
326+
if ($permState -eq "GrantWithGrant") {
327+
$grantWithGrant = "WITH GRANT OPTION"
328+
$permState = "GRANT"
329+
}
330+
else {
331+
$grantWithGrant = $null
332+
}
333+
334+
$outsql += "$permState $permType ON ENDPOINT::[$($endpoint.Name)] TO [$userName] $grantWithGrant AS [$grantor]"
335+
}
336+
337+
338+
}
316339
}
317340

318341
if ($NoDatabases -eq $false) {

0 commit comments

Comments
 (0)