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: Remove old helper functions #418

Merged
merged 5 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 41 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,42 @@
## Unreleased

- Changes to xActiveDirectory
- Added a Requirements section to every DSC resource README with the bullet point stating "Target machine must be running Windows Server 2008 R2 or later" ([issue #399](https://github.com/PowerShell/xActiveDirectory/issues/399)).
- Added 'about_\<DSCResource\>.help.txt' file to all resources ([issue #404](https://github.com/PowerShell/xActiveDirectory/issues/404)).
- Added a Requirements section to every DSC resource README with the
bullet point stating "Target machine must be running Windows Server
2008 R2 or later" ([issue #399](https://github.com/PowerShell/xActiveDirectory/issues/399)).
- Added 'about_\<DSCResource\>.help.txt' file to all resources
([issue #404](https://github.com/PowerShell/xActiveDirectory/issues/404)).
- Removed the helper function `ThrowInvalidOperationError` and
`ThrowInvalidArgumentError` in favor of the
[new helper functions for localization](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#helper-functions-for-localization)
([issue #316](https://github.com/PowerShell/xActiveDirectory/issues/316),
[issue #317](https://github.com/PowerShell/xActiveDirectory/issues/317)).
- Cleaned up some minor style violations in the code.
- Fixed an issue that the helper function `Add-ADCommonGroupMember` was
not outputting the correct group name in a verbose message and in an
error message.
- Changes to xADManagedServiceAccount
- Added a requirement to README stating "Group Managed Service Accounts need at least one Windows Server 2012 Domain Controller" ([issue #399](https://github.com/PowerShell/xActiveDirectory/issues/399)).
- Added a requirement to README stating "Group Managed Service Accounts
need at least one Windows Server 2012 Domain Controller"
([issue #399](https://github.com/PowerShell/xActiveDirectory/issues/399)).
- Changes to xADComputer
- Fixed the GUID in Example 3-AddComputerAccountSpecificPath_Config. ([issue #410](https://github.com/PowerShell/xActiveDirectory/issues/410)).
- Fixed the GUID in Example 3-AddComputerAccountSpecificPath_Config
([issue #410](https://github.com/PowerShell/xActiveDirectory/issues/410)).
- Changes to xADOrganizationalUnit
- Catch exception when the path property specifies a non-existing path ([issue #408](https://github.com/PowerShell/xActiveDirectory/issues/408)).
- Catch exception when the path property specifies a non-existing path
([issue #408](https://github.com/PowerShell/xActiveDirectory/issues/408)).
- Changes to xADUser
- Fixes exception when creating a user with an empty string property ([issue #407](https://github.com/PowerShell/xActiveDirectory/issues/407)).
- Fixes exception when updating `CommonName` and `Path` concurrently ([issue #402](https://github.com/PowerShell/xActiveDirectory/issues/402)).
- Fixes ChangePasswordAtLogon Property to be only set to `true` at User Creation ([issue #414](https://github.com/PowerShell/xActiveDirectory/issues/414)).
- Fixes exception when creating a user with an empty string property
([issue #407](https://github.com/PowerShell/xActiveDirectory/issues/407)).
- Fixes exception when updating `CommonName` and `Path` concurrently
([issue #402](https://github.com/PowerShell/xActiveDirectory/issues/402)).
- Fixes ChangePasswordAtLogon Property to be only set to `true` at User
Creation ([issue #414](https://github.com/PowerShell/xActiveDirectory/issues/414)).
- xADDomain
- Updated tests and replaced `Write-Error` with `throw`
([issue #332](https://github.com/PowerShell/xActiveDirectory/pull/332)).
- Changes to xADRecycleBin
- Updated tests and remove unnecessary mocks of `Write-Error`.

## 3.0.0.0

Expand Down Expand Up @@ -58,7 +82,8 @@
([issue #374](https://github.com/PowerShell/xActiveDirectory/issues/374)).
- Removed unused legacy test files from the root of the repository.
- Updated Example List README with missing resources.
- Added missing examples for xADReplicationSubnet, xADServicePrincipalName and xWaitForADDomain. ([issue #395](https://github.com/PowerShell/xActiveDirectory/issues/395)).
- Added missing examples for xADReplicationSubnet, xADServicePrincipalName
and xWaitForADDomain ([issue #395](https://github.com/PowerShell/xActiveDirectory/issues/395)).
- Changes to xADComputer
- Refactored the resource and the unit tests.
- BREAKING CHANGE: The `Enabled` property is **DEPRECATED** and is no
Expand Down Expand Up @@ -88,7 +113,8 @@
- Changes to xADOrganizationalUnit
- Change the description of the property RestoreFromRecycleBin.
- Code cleanup.
- Fix incorrect verbose message when this resource has Ensure set to Absent ([issue #276](https://github.com/PowerShell/xActiveDirectory/issues/276)).
- Fix incorrect verbose message when this resource has Ensure set to
Absent ([issue #276](https://github.com/PowerShell/xActiveDirectory/issues/276)).
- Changes to xADUser
- Change the description of the property RestoreFromRecycleBin.
- Added ServicePrincipalNames property ([issue #153](https://github.com/PowerShell/xActiveDirectory/issues/153)).
Expand Down Expand Up @@ -174,12 +200,14 @@
and [@kungfu71186](https://github.com/kungfu71186)
- Removing the Misc Folder, as it is no longer required.
- Added xADKDSKey resource to create KDS Root Keys for gMSAs. [@kungfu71186](https://github.com/kungfu71186)
- Combined DscResource.LocalizationHelper and DscResource.Common Modules into xActiveDirectory.Common
- Combined DscResource.LocalizationHelper and DscResource.Common Modules
into xActiveDirectory.Common
- Changes to xADReplicationSiteLink
- Make use of the new localization helper functions.
- Changes to xAdDomainController
- Added new parameter to disable or enable the Global Catalog (GC)
([issue #75](https://github.com/PowerShell/xActiveDirectory/issues/75)). [Eric Foskett @Merto410](https://github.com/Merto410)
([issue #75](https://github.com/PowerShell/xActiveDirectory/issues/75)).
[Eric Foskett @Merto410](https://github.com/Merto410)
- Fixed a bug with the parameter `InstallationMediaPath` that it would
not be added if it was specified in a configuration. Now the parameter
`InstallationMediaPath` is correctly passed to `Install-ADDSDomainController`.
Expand Down Expand Up @@ -323,7 +351,7 @@
- xADDomain: Added check for Active Directory cmdlets.
- xADDomain: Added additional error trapping, verbose and diagnostic information.
- xADDomain: Added unit test coverage.
- Fixes CredentialAttribute and other PSScriptAnalyzer tests in xADCommon, xADDomin, xADGroup, xADOrganizationalUnit and xADUser resources.
- Fixes CredentialAttribute and other PSScriptAnalyzer tests in xADCommon, xADDomain, xADGroup, xADOrganizationalUnit and xADUser resources.

## 2.9.0.0

Expand Down
4 changes: 2 additions & 2 deletions DSCResources/MSFT_xADDomain/MSFT_xADDomain.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Get-TargetResource
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
$errorMessage = $script:localizedData.ExistingDomainMemberError -f $DomainName
ThrowInvalidOperationError -ErrorId 'xADDomain_DomainMember' -ErrorMessage $errorMessage
New-ObjectNotFoundException -Message $errorMessage -ErrorRecord $_
}
catch [Microsoft.ActiveDirectory.Management.ADServerDownException]
{
Expand All @@ -161,7 +161,7 @@ function Get-TargetResource
catch [System.Security.Authentication.AuthenticationException]
{
$errorMessage = $script:localizedData.InvalidCredentialError -f $DomainName
ThrowInvalidOperationError -ErrorId 'xADDomain_InvalidCredential' -ErrorMessage $errorMessage
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion DSCResources/MSFT_xADGroup/MSFT_xADGroup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function Get-TargetResource
Write-Verbose -Message ($script:localizedData.RetrievingGroupMembers -f $MembershipAttribute)

# Retrieve the current list of members, returning the specified membership attribute
[System.Array]$adGroupMembers = (Get-ADGroupMember @adGroupParams).$MembershipAttribute
[System.Array] $adGroupMembers = (Get-ADGroupMember @adGroupParams).$MembershipAttribute

$targetResource = @{
GroupName = $adGroup.Name
Expand Down
15 changes: 4 additions & 11 deletions DSCResources/MSFT_xADUser/MSFT_xADUser.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1708,23 +1708,16 @@ function Assert-Parameters
# We cannot test/set passwords on disabled AD accounts
if (($PSBoundParameters.ContainsKey('Password')) -and ($Enabled -eq $false))
{
$throwInvalidArgumentErrorParams = @{
ErrorId = 'xADUser_DisabledAccountPasswordConflict'
ErrorMessage = $script:localizedData.PasswordParameterConflictError -f 'Enabled', $false, 'Password'
}

ThrowInvalidArgumentError @throwInvalidArgumentErrorParams
$errorMessage = $script:localizedData.PasswordParameterConflictError -f 'Enabled', $false, 'Password'
New-InvalidArgumentException -ArgumentName 'Password' -Message $errorMessage
}

# ChangePasswordAtLogon cannot be set for an account that also has PasswordNeverExpires set
if ($PSBoundParameters.ContainsKey('ChangePasswordAtLogon') -and $PSBoundParameters['ChangePasswordAtLogon'] -eq $true -and
$PSBoundParameters.ContainsKey('PasswordNeverExpires') -and $PSBoundParameters['PasswordNeverExpires'] -eq $true)
{
$throwInvalidArgumentErrorParams = @{
ErrorId = 'xADUser_ChangePasswordParameterConflict'
ErrorMessage = $script:localizedData.ChangePasswordParameterConflictError
}
ThrowInvalidArgumentError @throwInvalidArgumentErrorParams
$errorMessage = $script:localizedData.ChangePasswordParameterConflictError
New-InvalidArgumentException -ArgumentName 'ChangePasswordAtLogon, PasswordNeverExpires' -Message $errorMessage
}

} #end function Assert-Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ConvertFrom-StringData @'
MembersIsNullError = The Members parameter value is null. The '{0}' parameter must be provided if neither '{1}' nor '{2}' is provided. (ADCOMMON0012)
IncludeAndExcludeConflictError = The member '{0}' is included in both '{1}' and '{2}' parameter values. The same member must not be included in both '{1}' and '{2}' parameter values. (ADCOMMON0014)
IncludeAndExcludeAreEmptyError = The '{0}' and '{1}' parameters are either both null or empty. At least one member must be specified in one of these parameters. (ADCOMMON0015)
RecycleBinRestoreFailed = Restoring {0} ({1}) from the recycle bin failed. Error message: {2}. (ADCOMMON0017)
RecycleBinRestoreFailed = Failed restoring {0} ({1}) from the recycle bin. (ADCOMMON0017)
EmptyDomainError = No domain name retrieved for group member {0} in group {1}. (ADCOMMON0018)
CheckingMembers = Checking for '{0}' members. (ADCOMMON0019)
MembershipCountMismatch = Membership count is not correct. Expected '{0}' members, actual '{1}' members. (ADCOMMON0020)
Expand Down
78 changes: 15 additions & 63 deletions Modules/xActiveDirectory.Common/xActiveDirectory.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,8 @@ function Assert-Module

if (-not (Get-Module -Name $ModuleName -ListAvailable))
{
$errorId = '{0}_ModuleNotFound' -f $ModuleName
$errorMessage = $script:localizedData.RoleNotFoundError -f $moduleName
ThrowInvalidOperationError -ErrorId $errorId -ErrorMessage $errorMessage
New-ObjectNotFoundException -Message $errorMessage
}

if ($ImportModule)
Expand Down Expand Up @@ -623,16 +622,14 @@ function Assert-MemberParameters
if ($PSBoundParameters.ContainsKey('MembersToInclude') -or $PSBoundParameters.ContainsKey('MembersToExclude'))
{
# If Members are provided, Include and Exclude are not allowed.
$errorId = '{0}_MembersPlusIncludeOrExcludeConflict' -f $ModuleName
$errorMessage = $script:localizedData.MembersAndIncludeExcludeError -f 'Members', 'MembersToInclude', 'MembersToExclude'
ThrowInvalidArgumentError -ErrorId $errorId -ErrorMessage $errorMessage
New-InvalidArgumentException -ArgumentName 'Members' -Message $errorMessage
}

if ($Members.Length -eq 0)
{
$errorId = '{0}_MembersIsNull' -f $ModuleName
$errorMessage = $script:localizedData.MembersIsNullError -f 'Members', 'MembersToInclude', 'MembersToExclude'
ThrowInvalidArgumentError -ErrorId $errorId -ErrorMessage $errorMessage
New-InvalidArgumentException -ArgumentName 'Members' -Message $errorMessage
}
}

Expand All @@ -650,19 +647,17 @@ function Assert-MemberParameters
{
if (($MembersToInclude.Length -eq 0) -and ($MembersToExclude.Length -eq 0))
{
$errorId = '{0}_EmptyIncludeAndExclude' -f $ModuleName
$errorMessage = $script:localizedData.IncludeAndExcludeAreEmptyError -f 'MembersToInclude', 'MembersToExclude'
ThrowInvalidArgumentError -ErrorId $errorId -ErrorMessage $errorMessage
New-InvalidArgumentException -ArgumentName 'MembersToInclude, MembersToExclude' -Message $errorMessage
}

# Both MembersToInclude and MembersToExlude were provided. Check if they have common principals.
# Both MembersToInclude and MembersToExclude were provided. Check if they have common principals.
foreach ($member in $MembersToInclude)
{
if ($member -in $MembersToExclude)
{
$errorId = '{0}_IncludeAndExcludeConflict' -f $ModuleName
$errorMessage = $script:localizedData.IncludeAndExcludeConflictError -f $member, 'MembersToInclude', 'MembersToExclude'
ThrowInvalidArgumentError -ErrorId $errorId -ErrorMessage $errorMessage
New-InvalidArgumentException -ArgumentName 'MembersToInclude, MembersToExclude' -Message $errorMessage
}
}
}
Expand Down Expand Up @@ -715,7 +710,7 @@ function Remove-DuplicateMembers
} #end function RemoveDuplicateMembers

# Internal function to test whether the existing array members match the defined explicit array
# members, the included members are present and the exlcuded members are not present.
# members, the included members are present and the excluded members are not present.
function Test-Members
{
[CmdletBinding()]
Expand Down Expand Up @@ -887,7 +882,7 @@ function ConvertTo-TimeSpan

<#
.SYNOPSIS
Converts a System.TimeSpan into the number of seconds, mintutes, hours or days.
Converts a System.TimeSpan into the number of seconds, minutes, hours or days.

.PARAMETER TimeSpan
TimeSpan to convert into an integer
Expand Down Expand Up @@ -1039,51 +1034,6 @@ function Get-ADCommonParameters
return $adConnectionParameters
} #end function Get-ADCommonParameters

function ThrowInvalidOperationError
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ErrorId,

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

$exception = New-Object -TypeName 'System.InvalidOperationException' -ArgumentList $ErrorMessage
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation
$errorRecord = New-Object -TypeName 'System.Management.Automation.ErrorRecord' -ArgumentList @($exception, $ErrorId, $errorCategory, $null)
throw $errorRecord
}

function ThrowInvalidArgumentError
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$ErrorId,

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

$exception = New-Object -TypeName 'System.ArgumentException' -ArgumentList $ErrorMessage
$errorCategory = [System.Management.Automation.ErrorCategory]::InvalidArgument
$errorRecord = New-Object -TypeName 'System.Management.Automation.ErrorRecord' -ArgumentList @($exception, $ErrorId, $errorCategory, $null)
throw $errorRecord

} #end function ThrowInvalidArgumentError

# Internal function to test site availability
function Test-ADReplicationSite
{
Expand Down Expand Up @@ -1277,7 +1227,8 @@ function Restore-ADCommonObject
catch [Microsoft.ActiveDirectory.Management.ADException]
{
# After Get-TargetResource is through, only one error can occur here: Object parent does not exist
ThrowInvalidOperationError -ErrorId "$($Identity)_RecycleBinRestoreFailed" -ErrorMessage ($script:localizedData.RecycleBinRestoreFailed -f $Identity, $ObjectClass, $_.Exception.Message)
$errorMessage = $script:localizedData.RecycleBinRestoreFailed -f $Identity, $ObjectClass
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}

Expand Down Expand Up @@ -1359,11 +1310,14 @@ function Add-ADCommonGroupMember

if (-not $memberDomain)
{
ThrowInvalidArgumentError -ErrorId "$($member)_EmptyDomainError" -ErrorMessage ($script:localizedData.EmptyDomainError -f $member, $Parameters.GroupName)
$errorMessage = $script:localizedData.EmptyDomainError -f $member, $Parameters.Identity
New-InvalidOperationException -Message $errorMessage
}

Write-Verbose -Message ($script:localizedData.AddingGroupMember -f $member, $memberDomain, $Parameters.GroupName)
Write-Verbose -Message ($script:localizedData.AddingGroupMember -f $member, $memberDomain, $Parameters.Identity)

$memberObjectClass = (Get-ADObject -Identity $member -Server $memberDomain -Properties ObjectClass).ObjectClass

if ($memberObjectClass -eq 'computer')
{
$memberObject = Get-ADComputer -Identity $member -Server $memberDomain
Expand Down Expand Up @@ -1835,8 +1789,6 @@ Export-ModuleMember -Function @(
'ConvertTo-TimeSpan'
'ConvertFrom-TimeSpan'
'Get-ADCommonParameters'
'ThrowInvalidOperationError'
'ThrowInvalidArgumentError'
'Test-ADReplicationSite'
'ConvertTo-DeploymentForestMode'
'ConvertTo-DeploymentDomainMode'
Expand Down
Loading