diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b2571b..d512f743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - ADGroup - Refactored Module. - Refactored Unit and Integration Tests. + - Added SamAccountName property. ### Added diff --git a/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 b/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 index cdc22533..149c8a0a 100644 --- a/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 +++ b/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1 @@ -71,7 +71,7 @@ function Get-TargetResource Write-Verbose -Message ($script:localizedData.RetrievingGroup -f $GroupName) - $getADGroupProperties = ('Name', 'GroupScope', 'GroupCategory', 'DistinguishedName', 'Description', 'DisplayName', + $getADGroupProperties = ('Name', 'GroupScope', 'GroupCategory', 'DistinguishedName', 'Description', 'DisplayName', 'SamAccountName', 'ManagedBy', 'Members', 'Info') try @@ -163,6 +163,7 @@ function Get-TargetResource Path = Get-ADObjectParentDN -DN $adGroup.DistinguishedName Description = $adGroup.Description DisplayName = $adGroup.DisplayName + SamAccountName = $adGroup.SamAccountName Members = $adGroupMembers MembersToInclude = $null MembersToExclude = $null @@ -184,6 +185,7 @@ function Get-TargetResource Path = $null Description = $null DisplayName = $null + SamAccountName = $null Members = @() MembersToInclude = $null MembersToExclude = $null @@ -222,6 +224,9 @@ function Get-TargetResource .PARAMETER DisplayName Display name of the Active Directory group. + .PARAMETER SamAccountName + SamAccountName of the Active Directory group. + .PARAMETER Credential The credential to be used to perform the operation on Active Directory. @@ -299,6 +304,11 @@ function Test-TargetResource [System.String] $DisplayName, + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $SamAccountName, + [Parameter()] [ValidateNotNull()] [System.Management.Automation.PSCredential] @@ -474,6 +484,9 @@ function Test-TargetResource .PARAMETER DisplayName Display name of the Active Directory group. + .PARAMETER SamAccountName + SamAccountName of the Active Directory group. + .PARAMETER Credential The credential to be used to perform the operation on Active Directory. @@ -558,6 +571,11 @@ function Set-TargetResource [System.String] $DisplayName, + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $SamAccountName, + [Parameter()] [ValidateNotNull()] [System.Management.Automation.PSCredential] @@ -906,6 +924,11 @@ function Set-TargetResource $newAdGroupParameters['DisplayName'] = $DisplayName } + if ($PSBoundParameters.ContainsKey('SamAccountName')) + { + $newAdGroupParameters['SamAccountName'] = $SamAccountName + } + if ($PSBoundParameters.ContainsKey('ManagedBy')) { $newAdGroupParameters['ManagedBy'] = $ManagedBy diff --git a/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.schema.mof b/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.schema.mof index ac48c53f..9395e9e3 100644 --- a/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.schema.mof +++ b/source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.schema.mof @@ -8,6 +8,7 @@ class MSFT_ADGroup : OMI_BaseResource [Write, Description("Specifies if this Active Directory group should be present or absent. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Description of the Active Directory group.")] String Description; [Write, Description("Display name of the Active Directory group.")] String DisplayName; + [Write, Description("SamAccountName of the Active Directory group.")] String SamAccountName; [Write, Description("The credential to be used to perform the operation on Active Directory."), EmbeddedInstance("MSFT_Credential")] String Credential; [Write, Description("Active Directory domain controller to enact the change upon.")] String DomainController; [Write, Description("Active Directory group membership should match membership exactly.")] String Members[]; diff --git a/tests/Unit/MSFT_ADGroup.Tests.ps1 b/tests/Unit/MSFT_ADGroup.Tests.ps1 index 0ffe8192..a9c6bba7 100644 --- a/tests/Unit/MSFT_ADGroup.Tests.ps1 +++ b/tests/Unit/MSFT_ADGroup.Tests.ps1 @@ -43,6 +43,7 @@ try Path = 'OU=OU,DC=contoso,DC=com' Description = 'Test AD group description' DisplayName = 'Test display name' + SamAccountName = 'TestGroup' Ensure = 'Present' Notes = 'This is a test AD group' ManagedBy = 'CN=User 1,CN=Users,DC=contoso,DC=com' @@ -91,6 +92,7 @@ try Path = $mockGroupPath Description = 'Test AD group description' DisplayName = 'Test display name' + SamAccountName = $mockGroupName Info = 'This is a test AD group' ManagedBy = 'CN=User 1,CN=Users,DC=contoso,DC=com' DistinguishedName = "CN=$mockGroupName,$mockGroupPath" @@ -101,6 +103,7 @@ try GroupScope = 'Universal' Description = 'Test AD group description changed' DisplayName = 'Test display name changed' + SamAccountName = 'TestGroup2' ManagedBy = 'CN=User 2,CN=Users,DC=contoso,DC=com' } @@ -111,6 +114,7 @@ try Path = $mockADGroup.Path Description = $mockADGroup.Description DisplayName = $mockADGroup.DisplayName + SamAccountName = $mockAdGroup.SamAccountName Notes = $mockADGroup.Info ManagedBy = $mockADGroup.ManagedBy DistinguishedName = $mockADGroup.DistinguishedName @@ -125,6 +129,7 @@ try Path = $null Description = $null DisplayName = $null + SamAccountName = $null Notes = $null ManagedBy = $null DistinguishedName = $null @@ -162,6 +167,7 @@ try $result.Path | Should -Be $mockADGroup.Path $result.Description | Should -Be $mockADGroup.Description $result.DisplayName | Should -Be $mockADGroup.DisplayName + $result.SamAccountName | Should -Be $mockADGroup.SamAccountName $result.MembersToInclude | Should -BeNullOrEmpty $result.MembersToExclude | Should -BeNullOrEmpty $result.MembershipAttribute | Should -Be 'SamAccountName' @@ -338,6 +344,7 @@ try $result.Path | Should -BeNullOrEmpty $result.Description | Should -BeNullOrEmpty $result.DisplayName | Should -BeNullOrEmpty + $result.SamAccountName | Should -BeNullOrEmpty $result.Members | Should -BeNullOrEmpty $result.MembersToInclude | Should -BeNullOrEmpty $result.MembersToExclude | Should -BeNullOrEmpty @@ -369,6 +376,7 @@ try Path = $mockADGroup.Path Description = $mockADGroup.Description DisplayName = $mockADGroup.DisplayName + SamAccountName = $mockADGroup.SamAccountName ManagedBy = $mockADGroup.ManagedBy Notes = $mockADGroup.Info Members = $mockADGroup.Members @@ -552,6 +560,7 @@ try Path = $mockADGroup.Path Description = $mockADGroup.Description DisplayName = $mockADGroup.DisplayName + SamAccountName = $mockADGroup.SamAccountName ManagedBy = $mockADGroup.ManagedBy Notes = $mockADGroup.Info Members = $mockADGroup.Members