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

ADGroup: add SamAccountName parameter #658

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 24 additions & 1 deletion source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -184,6 +185,7 @@ function Get-TargetResource
Path = $null
Description = $null
DisplayName = $null
SamAccountName = $null
Members = @()
MembersToInclude = $null
MembersToExclude = $null
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -299,6 +304,11 @@ function Test-TargetResource
[System.String]
$DisplayName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SamAccountName,

[Parameter()]
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -558,6 +571,11 @@ function Set-TargetResource
[System.String]
$DisplayName,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SamAccountName,

[Parameter()]
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
Expand Down Expand Up @@ -906,6 +924,11 @@ function Set-TargetResource
$newAdGroupParameters['DisplayName'] = $DisplayName
}

if ($PSBoundParameters.ContainsKey('SamAccountName'))
{
$newAdGroupParameters['SamAccountName'] = $SamAccountName
}

if ($PSBoundParameters.ContainsKey('ManagedBy'))
{
$newAdGroupParameters['ManagedBy'] = $ManagedBy
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/MSFT_ADGroup/MSFT_ADGroup.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/MSFT_ADGroup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"
Expand All @@ -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'
}

Expand All @@ -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
Expand All @@ -125,6 +129,7 @@ try
Path = $null
Description = $null
DisplayName = $null
SamAccountName = $null
Notes = $null
ManagedBy = $null
DistinguishedName = $null
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down