From a644406137bfee6c80480244909282f9cc938429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimund=20Andr=C3=A9e=20=5BMSFT=5D?= Date: Fri, 22 Dec 2023 17:10:12 +0100 Subject: [PATCH] Added DFSR configurations and test data (#220) --- CHANGELOG.md | 6 +++ RequiredModules.psd1 | 2 +- .../DfsReplicationGroupConnections.psd1 | 15 +++++++ ...DfsReplicationGroupConnections.schema.psm1 | 42 +++++++++++++++++++ .../DfsReplicationGroupMembers.psd1 | 15 +++++++ .../DfsReplicationGroupMembers.schema.psm1 | 31 ++++++++++++++ .../DfsReplicationGroupMemberships.psd1 | 15 +++++++ ...DfsReplicationGroupMemberships.schema.psm1 | 40 ++++++++++++++++++ .../Config/DfsReplicationGroupConnections.yml | 13 ++++++ .../Config/DfsReplicationGroupMembers.yml | 7 ++++ .../Config/DfsReplicationGroupMemberships.yml | 11 +++++ 11 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.psd1 create mode 100644 source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.schema.psm1 create mode 100644 source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.psd1 create mode 100644 source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.schema.psm1 create mode 100644 source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.psd1 create mode 100644 source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.schema.psm1 create mode 100644 tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupConnections.yml create mode 100644 tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMembers.yml create mode 100644 tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMemberships.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 65420c0..edbe55a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - new composite to add a number of servers to a RDS deployment - DnsSuffixes - new resource to configure connection-specific DNS suffixes +- DfsReplicationGroupMembers + - new resource to configure DFSR group members +- DfsReplicationGroupMemberships + - new resource to configure DFSR group memberships +- DfsReplicationGroupConnections + - new resource to configure DFSR replication connections ### Changed diff --git a/RequiredModules.psd1 b/RequiredModules.psd1 index 65457ab..e494d7e 100644 --- a/RequiredModules.psd1 +++ b/RequiredModules.psd1 @@ -35,7 +35,7 @@ StorageDsc = '5.0.1' Chocolatey = '0.0.79' ActiveDirectoryDsc = '6.2.0' - DfsDsc = '4.4.0.0' + DFSDsc = '5.0.1' WdsDsc = '0.11.0' xDhcpServer = '3.1.0' xDscDiagnostics = '2.8.0' diff --git a/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.psd1 b/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.psd1 new file mode 100644 index 0000000..41e049b --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.psd1 @@ -0,0 +1,15 @@ +@{ + RootModule = 'DfsReplicationGroupConnections.schema.psm1' + + ModuleVersion = '0.0.1' + + GUID = '6b81b87e-3412-4a22-8b10-f06ef34e985f' + + Author = 'NA' + + CompanyName = 'NA' + + Copyright = 'NA' + + DscResourcesToExport = @('DfsReplicationGroupConnections') +} diff --git a/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.schema.psm1 b/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.schema.psm1 new file mode 100644 index 0000000..80e5631 --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupConnections/DfsReplicationGroupConnections.schema.psm1 @@ -0,0 +1,42 @@ +configuration DfsReplicationGroupConnections { + param ( + [Parameter(Mandatory = $true)] + [hashtable[]] + $Items + ) + + <# + DestinationComputerName = [string] + GroupName = [string] + SourceComputerName = [string] + [DependsOn = [string[]]] + [Description = [string]] + [DomainName = [string]] + [Ensure = [string]{ Absent | Present }] + [EnsureCrossFileRDCEnabled = [string]{ Disabled | Enabled }] + [EnsureEnabled = [string]{ Disabled | Enabled }] + [EnsureRDCEnabled = [string]{ Disabled | Enabled }] + [MinimumRDCFileSizeInKB = [UInt32]] + [PsDscRunAsCredential = [PSCredential]] + #> + + Import-DscResource -ModuleName PSDesiredStateConfiguration + Import-DscResource -ModuleName DFSDsc + + foreach ($item in $items) + { + if ($item.DestinationComputerName -eq $item.SourceComputerName) + { + Write-Warning "DestinationComputerName '$($item.DestinationComputerName)' and SourceComputerName '$($item.SourceComputerName)' cannot be the same. Skipping configuration item." + continue + } + + if (-not $item.ContainsKey('Ensure')) + { + $item.Ensure = 'Present' + } + + $executionName = "$($item.GroupName)__$($item.SourceComputerName)__$($item.DestinationComputerName)" -replace '[\s(){}/\\:-]', '_' + (Get-DscSplattedResource -ResourceName DFSReplicationGroupConnection -ExecutionName $executionName -Properties $item -NoInvoke).Invoke($item) + } +} diff --git a/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.psd1 b/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.psd1 new file mode 100644 index 0000000..a3b76a2 --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.psd1 @@ -0,0 +1,15 @@ +@{ + RootModule = 'DfsReplicationGroupMembers.schema.psm1' + + ModuleVersion = '0.0.1' + + GUID = 'e37629b2-45e9-43d2-81d9-50b4bbda9f86' + + Author = 'NA' + + CompanyName = 'NA' + + Copyright = 'NA' + + DscResourcesToExport = @('DfsReplicationGroupMembers') +} diff --git a/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.schema.psm1 b/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.schema.psm1 new file mode 100644 index 0000000..38e9ffb --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupMembers/DfsReplicationGroupMembers.schema.psm1 @@ -0,0 +1,31 @@ +configuration DfsReplicationGroupMembers { + param ( + [Parameter(Mandatory = $true)] + [hashtable[]] + $Items + ) + + <# + ComputerName = [string] + GroupName = [string] + [DependsOn = [string[]]] + [Description = [string]] + [DomainName = [string]] + [Ensure = [string]{ Absent | Present }] + [PsDscRunAsCredential = [PSCredential]] + #> + + Import-DscResource -ModuleName PSDesiredStateConfiguration + Import-DscResource -ModuleName DFSDsc + + foreach ($item in $items) + { + if (-not $item.ContainsKey('Ensure')) + { + $item.Ensure = 'Present' + } + + $executionName = "$($item.ComputerName)__$($item.GroupName)" -replace '[\s(){}/\\:-]', '_' + (Get-DscSplattedResource -ResourceName DFSReplicationGroupMember -ExecutionName $executionName -Properties $item -NoInvoke).Invoke($item) + } +} diff --git a/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.psd1 b/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.psd1 new file mode 100644 index 0000000..5abbcce --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.psd1 @@ -0,0 +1,15 @@ +@{ + RootModule = 'DfsReplicationGroupMemberships.schema.psm1' + + ModuleVersion = '0.0.1' + + GUID = '8ed7a563-658b-40bc-8f90-c77ec85b49f1' + + Author = 'NA' + + CompanyName = 'NA' + + Copyright = 'NA' + + DscResourcesToExport = @('DfsReplicationGroupMemberships') +} diff --git a/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.schema.psm1 b/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.schema.psm1 new file mode 100644 index 0000000..db52c8d --- /dev/null +++ b/source/DSCResources/DfsReplicationGroupMemberships/DfsReplicationGroupMemberships.schema.psm1 @@ -0,0 +1,40 @@ +configuration DfsReplicationGroupMemberships { + param ( + [Parameter(Mandatory = $true)] + [hashtable[]] + $Items + ) + + <# + ComputerName = [string] + FolderName = [string] + GroupName = [string] + [ConflictAndDeletedQuotaInMB = [UInt32]] + [ContentPath = [string]] + [DependsOn = [string[]]] + [DfsnPath = [string]] + [DomainName = [string]] + [EnsureEnabled = [string]{ Disabled | Enabled }] + [MinimumFileStagingSize = [string]{ Size128GB | Size128MB | Size128TB | Size16GB | Size16MB | Size16TB | Size1GB | Size1MB | Size1TB | Size256GB | Size256KB | Size256MB | Size256TB | Size2GB | Size2MB | Size2TB | Size32GB | Size32MB | Size32TB | Size4GB | Size4MB | Size4TB | Size512GB | Size512KB | Size512MB | Size512TB | Size64GB | Size64MB | Size64TB | Size8GB | Size8MB | Size8TB }] + [PrimaryMember = [bool]] + [PsDscRunAsCredential = [PSCredential]] + [ReadOnly = [bool]] + [RemoveDeletedFiles = [bool]] + [StagingPath = [string]] + [StagingPathQuotaInMB = [UInt32]] + #> + + Import-DscResource -ModuleName PSDesiredStateConfiguration + Import-DscResource -ModuleName DFSDsc + + foreach ($item in $items) + { + if (-not $item.ContainsKey('EnsureEnabled')) + { + $item.EnsureEnabled = 'Enabled' + } + + $executionName = "$($item.ComputerName)__$($item.FolderName)__$($item.GroupName)" -replace '[\s(){}/\\:-]', '_' + (Get-DscSplattedResource -ResourceName DFSReplicationGroupMembership -ExecutionName $executionName -Properties $item -NoInvoke).Invoke($item) + } +} diff --git a/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupConnections.yml b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupConnections.yml new file mode 100644 index 0000000..932ba9e --- /dev/null +++ b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupConnections.yml @@ -0,0 +1,13 @@ +Items: + - GroupName: Public + DomainName: contoso.com + SourceComputerName: server1.contoso.com + DestinationComputerName: server2.contoso.com + - GroupName: Public + DomainName: contoso.com + SourceComputerName: server1.contoso.com + DestinationComputerName: server3.contoso.com + - GroupName: Public + DomainName: contoso.com + SourceComputerName: server1.contoso.com + DestinationComputerName: server4.contoso.com diff --git a/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMembers.yml b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMembers.yml new file mode 100644 index 0000000..e074bc8 --- /dev/null +++ b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMembers.yml @@ -0,0 +1,7 @@ +Items: + - GroupName: Public + DomainName: contoso.com + ComputerName: server1.contoso.com + - GroupName: Public + DomainName: contoso.com + ComputerName: server2.contoso.com diff --git a/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMemberships.yml b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMemberships.yml new file mode 100644 index 0000000..52144b0 --- /dev/null +++ b/tests/Unit/DSCResources/Assets/Config/DfsReplicationGroupMemberships.yml @@ -0,0 +1,11 @@ +Items: + - GroupName: Public + FolderName: Test1 + ContentPath: C:\Data\Test1 + DomainName: contoso.com + ComputerName: server1.contoso.com + - GroupName: Public + FolderName: Test1 + ContentPath: C:\Data\Test1 + DomainName: contoso.com + ComputerName: server2.contoso.com