Skip to content

Commit abd9727

Browse files
authored
Merge pull request #5 from gerwintmg/patch-1
Add right that is not previously set [Set-UserRights.ps1]
2 parents 5c921f2 + 54aebf5 commit abd9727

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Powershell/General Functions/Set-UserRights.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
6969
Author: Blake Drumm (blakedrumm@microsoft.com)
7070
First Created on: January 5th, 2022
71-
Last Modified on: April 23rd, 2022
71+
Last Modified on: October 12th, 2022
7272
#>
7373
param
7474
(
@@ -223,12 +223,19 @@ PROCESS
223223
$sids = (Select-String $export -Pattern "$right").Line
224224
if ($ActionType -eq 'Adding')
225225
{
226-
$sidList = "$sids,*$sid"
226+
# If right has no value it needs to be added
227+
if($sids -eq $null) {
228+
$sids = "$right = *$sid"
229+
$sidList = $sids
230+
} else {
231+
$sidList = "$sids,*$sid"
232+
}
227233
}
228234
elseif ($ActionType -eq 'Removing')
229235
{
230236
$sidList = "$($sids.Replace("*$sid", '').Replace("$Username", '').Replace(",,", ',').Replace("= ,", '= '))"
231237
}
238+
Write-Verbose $sidlist
232239
foreach ($line in @("[Unicode]", "Unicode=yes", "[System Access]", "[Event Audit]", "[Registry Values]", "[Version]", "signature=`"`$CHICAGO$`"", "Revision=1", "[Profile Description]", "Description=$ActionType `"$UserLogonRight`" right for user account: $Username", "[Privilege Rights]", "$sidList"))
233240
{
234241
Add-Content $import $line
@@ -379,7 +386,7 @@ PROCESS
379386
else
380387
{
381388

382-
<# Edit line 392 to modify the default command run when this script is executed.
389+
<# Edit line 399 to modify the default command run when this script is executed.
383390
Example:
384391
Set-UserRights -AddRight -UserRight SeServiceLogonRight, SeBatchLogonRight -ComputerName $env:COMPUTERNAME, SQL.contoso.com -UserName CONTOSO\User1, CONTOSO\User2
385392
or

0 commit comments

Comments
 (0)