Public/Miscellaneous/Set-AdAclFullControlDHCP.ps1
Function Set-AdAclFullControlDHCP { <# .Synopsis Set delegation to fully manage Dynamic Host Configuration Protocol (DHCP) .DESCRIPTION Configures the configuration container to delegate the permissions to a group so it can fully manage Dynamic Host Configuration Protocol (DHCP). .EXAMPLE Set-AdAclFullControlDHCP -Group "SL_DHCPRight" .EXAMPLE Set-AdAclFullControlDHCP -Group "SL_DHCPRight" -RemoveRule .PARAMETER Group [STRING] Identity of the group getting the delegation. .PARAMETER RemoveRule [SWITCH] If present, the access rule will be removed .NOTES Used Functions: Name | Module ---------------------------------------|-------------------------- Set-AclConstructor5 | EguibarIT.DelegationPS Set-AclConstructor6 | EguibarIT.DelegationPS Get-AttributeSchemaHashTable | EguibarIT.DelegationPS .NOTES Version: 1.2 DateModified: 07/Dec/2016 LasModifiedBy: Vicente Rodriguez Eguibar vicente@eguibar.com Eguibar Information Technology S.L. http://www.eguibarit.com #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] [OutputType([void])] Param ( # PARAM1 STRING for the Delegated Group Name [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Identity of the group getting the delegation, usually a DomainLocal group.', Position = 0)] [ValidateNotNullOrEmpty()] [Alias('IdentityReference', 'Identity', 'Trustee', 'GroupID')] $Group, # PARAM3 SWITCH If present, the access rule will be removed. [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'If present, the access rule will be removed.', Position = 1)] [ValidateNotNullOrEmpty()] [Switch] $RemoveRule ) Begin { $txt = ($Variables.HeaderDelegation -f (Get-Date).ToShortDateString(), $MyInvocation.Mycommand, (Get-FunctionDisplay -HashTable $PsBoundParameters -Verbose:$False) ) Write-Verbose -Message $txt ############################## # Module imports ############################## # Variables Definition [Hashtable]$Splat = [hashtable]::New([StringComparer]::OrdinalIgnoreCase) Write-Verbose -Message 'Checking variable $Variables.GuidMap. In case is empty a function is called to fill it up.' Get-AttributeSchemaHashTable # Verify Group exist and return it as Microsoft.ActiveDirectory.Management.AdGroup $CurrentGroup = Get-AdObjectType -Identity $PSBoundParameters['Group'] } #end Begin Process { <# ACENumber : 1 IdentityReference : EguibarIT\xxx ActiveDirectoryRights : GenericAll AccessControlType : Allow ObjectType : GuidNULL InheritanceType : Descendents InheritedObjectType : dHCPClass [ClassSchema] IsInherited : False #> $Splat = @{ Id = $CurrentGroup LDAPPath = 'CN=NetServices,CN=Services,{0}' -f $Variables.configurationNamingContext AdRight = 'GenericAll' AccessControlType = 'Allow' ObjectType = $Constants.GuidNULL AdSecurityInheritance = 'Descendents' InheritedObjectType = $Variables.GuidMap['dHCPClass'] } # Check if RemoveRule switch is present. If ($PSBoundParameters['RemoveRule']) { if ($Force -or $PSCmdlet.ShouldProcess($PSBoundParameters['Group'], 'Remove permissions for dHCPClass?')) { # Add the parameter to remove the rule $Splat.Add('RemoveRule', $true) } #end If } #end If If ($Force -or $PSCmdlet.ShouldProcess($PSBoundParameters['Group'], 'Delegate the permissions for dHCPClass?')) { Set-AclConstructor6 @Splat } #end If <# ACENumber : 2 IdentityReference : EguibarIT\xxx ActiveDirectoryRights : CreateChild, DeleteChild AccessControlType : Allow ObjectType : dHCPClass [ClassSchema] InheritanceType : None InheritedObjectType : GuidNULL IsInherited : False #> $Splat = @{ Id = $CurrentGroup LDAPPath = 'CN=NetServices,CN=Services,{0}' -f $Variables.configurationNamingContext AdRight = 'CreateChild', 'DeleteChild' AccessControlType = 'Allow' ObjectType = $Variables.GuidMap['dHCPClass'] AdSecurityInheritance = 'None' } # Check if RemoveRule switch is present. If ($PSBoundParameters['RemoveRule']) { if ($Force -or $PSCmdlet.ShouldProcess($PSBoundParameters['Group'], 'Remove permissions for dHCPClass?')) { # Add the parameter to remove the rule $Splat.Add('RemoveRule', $true) } #end If } #end If If ($Force -or $PSCmdlet.ShouldProcess($PSBoundParameters['Group'], 'Delegate the permissions for dHCPClass?')) { Set-AclConstructor5 @Splat } #end If } #end Process End { if ($RemoveRule) { Write-Verbose ('Permissions removal process completed for group: {0}' -f $PSBoundParameters['Group']) } else { Write-Verbose ('Permissions delegation process completed for group: {0} ' -f $PSBoundParameters['Group']) } #end If-Else $txt = ($Variables.FooterDelegation -f $MyInvocation.InvocationName, 'delegating DHCP.' ) Write-Verbose -Message $txt } #end END } |