Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xActiveDirectory: Cleanup code #326

Merged
merged 29 commits into from
Jun 16, 2019
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c165632
Remove semicolon from rows
johlju Jun 7, 2019
7d2ed6b
Update CHANGELOG.md
johlju Jun 7, 2019
8aff5a7
Migrate tests to Pester syntax v4.x (issue #322)
johlju Jun 7, 2019
d4b25a0
Removed `-MockWith {}` in unit tests.
johlju Jun 7, 2019
93fb0d2
Changes to xADRecycleBin
johlju Jun 7, 2019
6b76655
Changes to xADRecycleBin
johlju Jun 7, 2019
75d0b93
Changes to xADDomainDefaultPasswordPolicy
johlju Jun 7, 2019
5a0df70
Changes to xADDomainTrust
johlju Jun 7, 2019
0530c55
Changes to xADForestProperties
johlju Jun 7, 2019
9e9bcac
Changes to xADGroup
johlju Jun 7, 2019
8560659
Changes to xADOrganizationalUnit
johlju Jun 7, 2019
a4d033a
Changes to xADUser
johlju Jun 7, 2019
028f8ac
Changes to xWaitForADDomain
johlju Jun 7, 2019
334ce72
Add VSCode code formatting
johlju Jun 7, 2019
f63b18e
Add verbose in xADRecycleBin
johlju Jun 7, 2019
d6ea286
Fix typo in xADObjectPermissionEntry.Tests
johlju Jun 7, 2019
09e41f1
Typ in xWaitForADDomain.Tests
johlju Jun 7, 2019
e3646a8
Fix CHANGELOG.md after rebase
johlju Jun 13, 2019
1c01c35
Fix full stop
johlju Jun 15, 2019
c0f0fe4
Fix comment that did not match style guideline
johlju Jun 15, 2019
b968759
Fix if-blocks
johlju Jun 15, 2019
d06e883
Fix named parameters on New-Object
johlju Jun 15, 2019
22b6b62
Fix named parameters on Where-Object
johlju Jun 15, 2019
08c7704
Remove semi-colon from missed file
johlju Jun 15, 2019
0b984f6
Fixed missed comment block
johlju Jun 15, 2019
b1b6147
Remove BOM from file
johlju Jun 15, 2019
b638593
Fix review comments at r3
johlju Jun 15, 2019
006e836
Fix Pester syntax in recent merges
johlju Jun 15, 2019
acc3c78
Update CHANGELOG.md
johlju Jun 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changes to xADOrganizationalUnit
- Code cleanup.
johlju committed Jun 15, 2019

Verified

This commit was signed with the committer’s verified signature.
kanadgupta Kanad Gupta
commit 8560659652e05493479d0910721ea50682169f42
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@
- Fix unnecessary cast in `Test-TargetResource` ([Issue #295](https://github.com/PowerShell/xActiveDirectory/issues/295))
- Changes to xADGroup
- Change the description of the property RestoreFromRecycleBin.
- Cleanup of code.
- Code cleanup.
- Changes to xADObjectPermissionEntry
- Change the description of the property IdentityReference.
- Fix failure when applied in the same configuration as xADDomain
@@ -80,7 +80,7 @@
a reboot.
- Changes to xADDomainTrust
- Replaced New-TerminatingError with Standard Function.
- Cleanup of code.
- Code cleanup.
- Changes to xWaitForADDomain
- Suppressing the Script Analyzer rule `PSAvoidGlobalVars` since the
resource is using the `$global:DSCMachineStatus` variable to trigger
@@ -89,7 +89,7 @@
- Changes to xADRecycleBin
- Remove unneeded example and resource designer files.
- Added missing property schema descriptions ([issue #368](https://github.com/PowerShell/xActiveDirectory/issues/368)).
- Cleanup of code.
- Code cleanup.
- It now set back the `$ErrorActionPreference` that was set prior to
setting it to `'Stop'`.
- Changes to xADReplicationSiteLink
@@ -101,9 +101,13 @@
- Remove `{ *Present* | Absent }` from the property schema descriptions
which were causing corruption in the Wiki documentation.
- Changes to xADDomainDefaultPasswordPolicy
- Cleanup of code.
- Code cleanup.
- Changes to xADDomainTrust
- Code cleanup.
- Changes to xADForestProperties
- Minor style cleanup.
- Changes to xADOrganizationalUnit
- Code cleanup.

## 2.26.0.0

Original file line number Diff line number Diff line change
@@ -13,25 +13,36 @@ function Get-TargetResource
param
(
[Parameter(Mandatory = $true)]
[System.String] $Name,
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.String] $Path
[System.String]
$Path
)

Assert-Module -ModuleName 'ActiveDirectory'

Write-Verbose ($script:localizedData.RetrievingOU -f $Name)

$ou = Get-ADOrganizationalUnit -Filter { Name -eq $Name } -SearchBase $Path -SearchScope OneLevel -Properties ProtectedFromAccidentalDeletion, Description

$targetResource = @{
Name = $Name
Path = $Path
Ensure = if ($null -eq $ou) { 'Absent' } else { 'Present' }
ProtectedFromAccidentalDeletion = $ou.ProtectedFromAccidentalDeletion
Description = $ou.Description
if ($null -eq $ou)
{
$ensureState = 'Absent'
}
else
{
$ensureState = 'Present'
}
return $targetResource

return @{
Name = $Name
Path = $Path
Ensure = $ensureState
ProtectedFromAccidentalDeletion = $ou.ProtectedFromAccidentalDeletion
Description = $ou.Description
}
} # end function Get-TargetResource

function Test-TargetResource
@@ -41,10 +52,12 @@ function Test-TargetResource
param
(
[Parameter(Mandatory = $true)]
[System.String] $Name,
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.String] $Path,
[System.String]
$Path,

[Parameter()]
[ValidateSet('Present', 'Absent')]
@@ -59,11 +72,13 @@ function Test-TargetResource

[Parameter()]
[ValidateNotNull()]
[System.Boolean] $ProtectedFromAccidentalDeletion = $true,
[System.Boolean]
$ProtectedFromAccidentalDeletion = $true,

[Parameter()]
[ValidateNotNull()]
[System.String] $Description = '',
[System.String]
$Description = '',

[Parameter()]
[ValidateNotNull()]
@@ -81,15 +96,15 @@ function Test-TargetResource
if ([System.String]::IsNullOrEmpty($Description))
{
$isCompliant = (($targetResource.Name -eq $Name) -and
($targetResource.Path -eq $Path) -and
($targetResource.ProtectedFromAccidentalDeletion -eq $ProtectedFromAccidentalDeletion))
($targetResource.Path -eq $Path) -and
($targetResource.ProtectedFromAccidentalDeletion -eq $ProtectedFromAccidentalDeletion))
}
else
{
$isCompliant = (($targetResource.Name -eq $Name) -and
($targetResource.Path -eq $Path) -and
($targetResource.ProtectedFromAccidentalDeletion -eq $ProtectedFromAccidentalDeletion) -and
($targetResource.Description -eq $Description))
($targetResource.Path -eq $Path) -and
($targetResource.ProtectedFromAccidentalDeletion -eq $ProtectedFromAccidentalDeletion) -and
($targetResource.Description -eq $Description))
}

if ($isCompliant)
@@ -132,10 +147,12 @@ function Set-TargetResource
param
(
[Parameter(Mandatory = $true)]
[System.String] $Name,
[System.String]
$Name,

[Parameter(Mandatory = $true)]
[System.String] $Path,
[System.String]
$Path,

[Parameter()]
[ValidateSet('Present', 'Absent')]
@@ -150,11 +167,13 @@ function Set-TargetResource

[Parameter()]
[ValidateNotNull()]
[System.Boolean] $ProtectedFromAccidentalDeletion = $true,
[System.Boolean]
$ProtectedFromAccidentalDeletion = $true,

[Parameter()]
[ValidateNotNull()]
[System.String] $Description = '',
[System.String]
$Description = '',

[Parameter()]
[ValidateNotNull()]
@@ -163,58 +182,69 @@ function Set-TargetResource
)

Assert-Module -ModuleName 'ActiveDirectory'

$targetResource = Get-TargetResource -Name $Name -Path $Path

if ($targetResource.Ensure -eq 'Present')
{
$ou = Get-ADOrganizationalUnit -Filter { Name -eq $Name } -SearchBase $Path -SearchScope OneLevel

if ($Ensure -eq 'Present')
{
Write-Verbose ($script:localizedData.UpdatingOU -f $targetResource.Name)

$setADOrganizationalUnitParams = @{
Identity = $ou
Description = $Description
Identity = $ou
Description = $Description
ProtectedFromAccidentalDeletion = $ProtectedFromAccidentalDeletion
}

if ($Credential)
{
$setADOrganizationalUnitParams['Credential'] = $Credential
}

Set-ADOrganizationalUnit @setADOrganizationalUnitParams
}
else
{
Write-Verbose ($script:localizedData.DeletingOU -f $targetResource.Name)

if ($targetResource.ProtectedFromAccidentalDeletion)
{
$setADOrganizationalUnitParams = @{
Identity = $ou
Identity = $ou
ProtectedFromAccidentalDeletion = $ProtectedFromAccidentalDeletion
}

if ($Credential)
{
$setADOrganizationalUnitParams['Credential'] = $Credential
}

Set-ADOrganizationalUnit @setADOrganizationalUnitParams
}

$removeADOrganizationalUnitParams = @{
Identity = $ou
}

if ($Credential)
{
$removeADOrganizationalUnitParams['Credential'] = $Credential
}

Remove-ADOrganizationalUnit @removeADOrganizationalUnitParams
}

return # return from Set method to make it easier to test for a succesful restore
return # return from Set method to make it easier to test for a successful restore
}
else
{
if ($RestoreFromRecycleBin)
if ($RestoreFromRecycleBin)
{
Write-Verbose -Message ($script:localizedData.RestoringOu -f $Name)

$restoreParams = @{
Identity = $Name
ObjectClass = 'OrganizationalUnit'
@@ -232,16 +262,19 @@ function Set-TargetResource
if (-not $RestoreFromRecycleBin -or ($RestoreFromRecycleBin -and -not $restoreSuccessful))
{
Write-Verbose ($script:localizedData.CreatingOU -f $targetResource.Name)

$newADOrganizationalUnitParams = @{
Name = $Name
Path = $Path
Description = $Description
Name = $Name
Path = $Path
Description = $Description
ProtectedFromAccidentalDeletion = $ProtectedFromAccidentalDeletion
}

if ($Credential)
{
$newADOrganizationalUnitParams['Credential'] = $Credential
}

New-ADOrganizationalUnit @newADOrganizationalUnitParams
}
}