Skip to content

Commit

Permalink
Fix overflow error due script validation and empty attributes within …
Browse files Browse the repository at this point in the history
…splatting.
  • Loading branch information
vreguibar committed Jun 4, 2024
1 parent ffd291a commit 58c6de9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
51 changes: 36 additions & 15 deletions Public/New-DelegateAdOU.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function New-DelegateAdOU {
HelpMessage = 'LDAP path where this ou will be created',
Position = 1)]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-IsValidDN -ObjectDN $_ })]
[Alias('DN', 'DistinguishedName', 'LDAPpath')]
[string]
$ouPath,
Expand Down Expand Up @@ -215,35 +214,57 @@ function New-DelegateAdOU {
Write-Verbose -Message ('Creating the {0} Organizational Unit' -f $PSBoundParameters['ouName'])
# Create OU
$Splat = @{
Name = $PSBoundParameters['ouName']
Name = $ouName
Path = $PSBoundParameters['ouPath']
City = $PSBoundParameters['ouCity']
Country = $PSBoundParameters['ouCountry']
Description = $PSBoundParameters['ouDescription']
DisplayName = $PSBoundParameters['strOuDisplayName']
PostalCode = $PSBoundParameters['ouZIPCode']
ProtectedFromAccidentalDeletion = $true
StreetAddress = $PSBoundParameters['ouStreetAddress']
State = $PSBoundParameters['ouState']
}

if ($PSBoundParameters['ouCity']) {
$Splat.City = $PSBoundParameters['ouCity']
}
if ($PSBoundParameters['ouCountry']) {
$Splat.Country = $PSBoundParameters['ouCountry']
}
if ($PSBoundParameters['ouDescription']) {
$Splat.Description = $PSBoundParameters['ouDescription']
}
if ($PSBoundParameters['strOuDisplayName']) {
$Splat.DisplayName = $PSBoundParameters['strOuDisplayName']
}
if ($PSBoundParameters['ouZIPCode']) {
$Splat.PostalCode = $PSBoundParameters['ouZIPCode']
}
if ($PSBoundParameters['ouStreetAddress']) {
$Splat.StreetAddress = $PSBoundParameters['ouStreetAddress']
}
if ($PSBoundParameters['ouState']) {
$Splat.State = $PSBoundParameters['ouState']
}

if ($PSCmdlet.ShouldProcess("Creating the Organizational Unit '$OuName'")) {
$OUexists = New-ADOrganizationalUnit @Splat
}
} #end If-Else
} catch {
Write-Error -Message ('Error creating OU: {0}' -f $_)
###Get-CurrentErrorToDisplay -CurrentError $error[0]
throw
} #end Try-Catch

# Remove "Account Operators" and "Print Operators" built-in groups from OU. Any unknown/UnResolvable SID will be removed.
Start-AdCleanOU -LDAPpath $ouNameDN -RemoveUnknownSIDs

if ($PSBoundParameters['CleanACL']) {
if ($PSCmdlet.ShouldProcess("Removing specific Non-Inherited ACE and enabling inheritance for '$OuName'")) {
#Remove-SpecificACLandEnableInheritance -LDAPpath $ouNameDN
Revoke-Inheritance -LDAPpath $ouNameDN -RemoveInheritance -KeepPermissions
}
} #end If
try {
if ($PSBoundParameters['CleanACL']) {
if ($PSCmdlet.ShouldProcess("Removing specific Non-Inherited ACE and enabling inheritance for '$OuName'")) {
#Remove-SpecificACLandEnableInheritance -LDAPpath $ouNameDN
Revoke-Inheritance -LDAPpath $ouNameDN -RemoveInheritance -KeepPermissions
}
} #end If
} catch {
Write-Error -Message ('Error cleaning ACL: {0}' -f $_)
throw
} #end Try-Catch
} #end Process

End {
Expand Down
2 changes: 1 addition & 1 deletion Public/New-LapsObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Function New-LAPSobject {
ValueFromRemainingArguments = $false,
HelpMessage = 'Full path to the configuration.xml file',
Position = 0)]
[string]
[System.IO.FileInfo]
$ConfigXMLFile
)
Begin {
Expand Down

0 comments on commit 58c6de9

Please sign in to comment.