2323 This parameter accepts pipeline input.
2424
2525 . PARAMETER Grant
26- Specifies the permissions that should be granted. Any existing granted
27- permissions not in this list will be revoked.
26+ Specifies the permissions that should be granted. The permissions specified
27+ will be the exact granted permissions - any existing granted permissions not
28+ in this list will be revoked. If this parameter is omitted (not specified),
29+ existing Grant permissions are left unchanged.
2830
2931 . PARAMETER GrantWithGrant
3032 Specifies the permissions that should be granted with the grant option.
31- Any existing grant-with-grant permissions not in this list will be revoked.
33+ The permissions specified will be the exact grant-with-grant permissions -
34+ any existing grant-with-grant permissions not in this list will be revoked.
35+ If this parameter is omitted (not specified), existing GrantWithGrant
36+ permissions are left unchanged.
3237
3338 . PARAMETER Deny
34- Specifies the permissions that should be denied. Any existing denied
35- permissions not in this list will be revoked.
39+ Specifies the permissions that should be denied. The permissions specified
40+ will be the exact denied permissions - any existing denied permissions not
41+ in this list will be revoked. If this parameter is omitted (not specified),
42+ existing Deny permissions are left unchanged.
3643
3744 . PARAMETER Force
3845 Specifies that the permissions should be set without any confirmation.
8390 where the permissions will be set. If specifying `-ErrorAction 'SilentlyContinue'`
8491 then the command will silently continue if any errors occur. If specifying
8592 `-ErrorAction 'Stop'` the command will throw an error on any failure.
93+
94+ > [!IMPORTANT]
95+ > This command only modifies permission categories that are explicitly specified.
96+ > If you omit a parameter (e.g., don't specify `-Grant`), permissions in that
97+ > category are left unchanged. However, if you specify a parameter (even as an
98+ > empty array like `-Grant @()`), the command sets exact permissions for that
99+ > category only - revoking any permissions not in the list. This allows you to
100+ > independently manage Grant, GrantWithGrant, and Deny permissions without
101+ > affecting the other categories.
86102#>
87103function Set-SqlDscServerPermission
88104{
@@ -103,17 +119,17 @@ function Set-SqlDscServerPermission
103119 [Parameter ()]
104120 [AllowEmptyCollection ()]
105121 [SqlServerPermission []]
106- $Grant = @ () ,
122+ $Grant ,
107123
108124 [Parameter ()]
109125 [AllowEmptyCollection ()]
110126 [SqlServerPermission []]
111- $GrantWithGrant = @ () ,
127+ $GrantWithGrant ,
112128
113129 [Parameter ()]
114130 [AllowEmptyCollection ()]
115131 [SqlServerPermission []]
116- $Deny = @ () ,
132+ $Deny ,
117133
118134 [Parameter ()]
119135 [System.Management.Automation.SwitchParameter ]
@@ -185,15 +201,35 @@ function Set-SqlDscServerPermission
185201 }
186202 }
187203
188- # Calculate what needs to be revoked (permissions in current state but not in desired state)
189- $grantToRevoke = $currentGrant | Where-Object - FilterScript { $_ -notin $Grant }
190- $grantWithGrantToRevoke = $currentGrantWithGrant | Where-Object - FilterScript { $_ -notin $GrantWithGrant }
191- $denyToRevoke = $currentDeny | Where-Object - FilterScript { $_ -notin $Deny }
204+ # Calculate what needs to be revoked and added
205+ # Only process permission categories that were explicitly specified via parameters
206+ $grantToRevoke = @ ()
207+ $grantToAdd = @ ()
208+ $grantWithGrantToRevoke = @ ()
209+ $grantWithGrantToAdd = @ ()
210+ $denyToRevoke = @ ()
211+ $denyToAdd = @ ()
212+
213+ # Only process Grant permissions if the parameter was explicitly specified
214+ if ($PSBoundParameters.ContainsKey (' Grant' ))
215+ {
216+ $grantToRevoke = $currentGrant | Where-Object - FilterScript { $_ -notin $Grant }
217+ $grantToAdd = $Grant | Where-Object - FilterScript { $_ -notin $currentGrant }
218+ }
219+
220+ # Only process GrantWithGrant permissions if the parameter was explicitly specified
221+ if ($PSBoundParameters.ContainsKey (' GrantWithGrant' ))
222+ {
223+ $grantWithGrantToRevoke = $currentGrantWithGrant | Where-Object - FilterScript { $_ -notin $GrantWithGrant }
224+ $grantWithGrantToAdd = $GrantWithGrant | Where-Object - FilterScript { $_ -notin $currentGrantWithGrant }
225+ }
192226
193- # Calculate what needs to be granted/denied (permissions in desired state but not in current state)
194- $grantToAdd = $Grant | Where-Object - FilterScript { $_ -notin $currentGrant }
195- $grantWithGrantToAdd = $GrantWithGrant | Where-Object - FilterScript { $_ -notin $currentGrantWithGrant }
196- $denyToAdd = $Deny | Where-Object - FilterScript { $_ -notin $currentDeny }
227+ # Only process Deny permissions if the parameter was explicitly specified
228+ if ($PSBoundParameters.ContainsKey (' Deny' ))
229+ {
230+ $denyToRevoke = $currentDeny | Where-Object - FilterScript { $_ -notin $Deny }
231+ $denyToAdd = $Deny | Where-Object - FilterScript { $_ -notin $currentDeny }
232+ }
197233
198234 # Revoke permissions that should no longer exist
199235 if ($grantToRevoke -and $grantToRevoke.Count -gt 0 )
0 commit comments