103103
104104 Author: Blake Drumm (blakedrumm@microsoft.com)
105105 First Created on: January 5th, 2022
106- Last Modified on: December 22nd, 2023
106+ Last Modified on: October 12th, 2022
107107#>
108108param
109109(
@@ -128,6 +128,7 @@ param
128128)
129129BEGIN
130130{
131+
131132 Write-Output ' ==================================================================='
132133 Write-Output ' ========================== Start of Script ======================='
133134 Write-Output ' ==================================================================='
@@ -182,66 +183,6 @@ PROCESS
182183 [Alias (' right' )]
183184 [array ]$UserRight
184185 )
185- Add-Type - AssemblyName " System.DirectoryServices.AccountManagement"
186-
187- $TypeLoaded = [AppDomain ]::CurrentDomain.GetAssemblies() |
188- Where-Object { $_.FullName -like " *System.DirectoryServices.AccountManagement*" }
189-
190- if (-NOT $TypeLoaded )
191- {
192- Write-Warning " Unable to load 'System.DirectoryServices.AccountManagement' type in the PowerShell script."
193- break
194- }
195-
196- function Is-GroupName
197- {
198- param (
199- [string ]$name
200- )
201-
202- try
203- {
204- $contextType = [System.DirectoryServices.AccountManagement.ContextType ]::Domain
205- $principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($contextType )
206-
207- # Attempt to find the group in the domain
208- $groupPrincipal = [System.DirectoryServices.AccountManagement.GroupPrincipal ]::FindByIdentity($principalContext , $name )
209-
210- if ($groupPrincipal -ne $null )
211- {
212- return $true
213- }
214-
215- # If not found in domain, check local machine
216- $contextType = [System.DirectoryServices.AccountManagement.ContextType ]::Machine
217- $principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($contextType )
218-
219- $groupPrincipal = [System.DirectoryServices.AccountManagement.GroupPrincipal ]::FindByIdentity($principalContext , $name )
220-
221- return $groupPrincipal -ne $null
222- }
223- catch
224- {
225- Write-Warning " Error occurred while checking group: $_ "
226- return $false
227- }
228- }
229-
230- foreach ($item in $Username )
231- {
232- if (Is- GroupName - name $item )
233- {
234- Write-Host " $ ( Time- Stamp) $item is a group."
235- $userType = ' Group'
236- }
237- else
238- {
239- Write-Host " $ ( Time- Stamp) $item is a user."
240- $userType = ' User'
241- }
242- }
243-
244-
245186 if (! $UserRight )
246187 {
247188 Write-Warning " Inner Function: Unable to continue because you did not supply the '-UserRight' parameter."
@@ -312,7 +253,6 @@ PROCESS
312253 {
313254 $sid = ((New-Object System.Security.Principal.NTAccount($Username )).Translate([System.Security.Principal.SecurityIdentifier ])).Value
314255 }
315- Write-Verbose " $userType ($Username ) SID: $sid "
316256 secedit / export / cfg $export | Out-Null
317257 # Change the below to any right you would like
318258 $sids = (Select-String $export - Pattern " $right " ).Line
@@ -343,13 +283,13 @@ PROCESS
343283 secedit / import / db $secedt / cfg $import | Out-Null
344284 secedit / configure / db $secedt | Out-Null
345285 gpupdate / force | Out-Null
286+ Write-Verbose " The script will not delete the following paths due to running in verbose mode, please remove these files manually if needed:"
287+ Write-Verbose " `$ import : $import "
288+ Write-Verbose " `$ export : $export "
289+ Write-Verbose " `$ secedt : $secedt "
346290
347291 if ($VerbosePreference.value__ -eq 0 )
348292 {
349- Write-Verbose " The script will not delete the following paths due to running in verbose mode, please remove these files manually if needed:"
350- Write-Verbose " `$ import : $import "
351- Write-Verbose " `$ export : $export "
352- Write-Verbose " `$ secedt : $secedt "
353293 Remove-Item - Path $import - Force | Out-Null
354294 Remove-Item - Path $export - Force | Out-Null
355295 Remove-Item - Path $secedt - Force | Out-Null
@@ -484,20 +424,17 @@ PROCESS
484424 else
485425 {
486426
487- <# Edit line 500 to modify the default command run when this script is executed.
488-
489- Example:
427+ <# Edit line 437 to modify the default command run when this script is executed.
428+ Example:
490429 Set-UserRights -AddRight -UserRight SeServiceLogonRight, SeBatchLogonRight -ComputerName $env:COMPUTERNAME, SQL.contoso.com -UserName CONTOSO\User1, CONTOSO\User2
491430 or
492431 Set-UserRights -AddRight -UserRight SeBatchLogonRight -Username S-1-5-11
493- or
494- Set-UserRights -AddRight -UserRight SeServiceLogonRight, SeBatchLogonRight -Username Administrators
495432 or
496433 Set-UserRights -RemoveRight -UserRight SeBatchLogonRight -Username CONTOSO\User2
497434 or
498435 Set-UserRights -RemoveRight -UserRight SeServiceLogonRight, SeBatchLogonRight -Username CONTOSO\User1
499436 #>
500- Set-UserRights - AddRight - UserRight SeServiceLogonRight - Username Administrators - Verbose
437+ Set-UserRights
501438 }
502439}
503440END
0 commit comments