Update Workflows/Windows/Windows Server/Roles/DFS/Creating and Configuring DFS Namespaces with Replication.md
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				GitOps Automatic Deployment / GitOps Automatic Deployment (push) Successful in 8s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	GitOps Automatic Deployment / GitOps Automatic Deployment (push) Successful in 8s
				
			This commit is contained in:
		| @@ -124,48 +124,53 @@ In the Replication wizard that appears after about a minute, you can configure t | |||||||
| ### Checking DFS Status | ### Checking DFS Status | ||||||
| You may want to put together a simple table report of the DFS namespaces, replication info, and target folders.  You can run the following powershell script to generate a nice table-based report of the current structure of the DFS namespaces in your domain. | You may want to put together a simple table report of the DFS namespaces, replication info, and target folders.  You can run the following powershell script to generate a nice table-based report of the current structure of the DFS namespaces in your domain. | ||||||
|  |  | ||||||
| ```powershell | ??? example "Powershell Reporting Script" | ||||||
| [CmdletBinding()] |     ```powershell | ||||||
| param( |     # Automatically detect current AD domain and use it as DFS prefix | ||||||
|   [string]$DomainPrefix = "\\bunny-lab.io"  # Adjust if Different |     try { | ||||||
| ) |         $Domain = ([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name | ||||||
|  |         $DomainPrefix = "\\$Domain" | ||||||
|  |     } catch { | ||||||
|  |         Write-Warning "Unable to detect domain automatically. Falling back to manual value." | ||||||
|  |         $DomainPrefix = "\\bunny-lab.io" | ||||||
|  |     } | ||||||
|  |  | ||||||
| Import-Module DFSN -ErrorAction Stop |     Import-Module DFSN -ErrorAction Stop | ||||||
| Import-Module DFSR -ErrorAction Stop |     Import-Module DFSR -ErrorAction Stop | ||||||
|  |  | ||||||
| function Get-ServerNameFromPath { |     function Get-ServerNameFromPath { | ||||||
|       param([string]$Path) |       param([string]$Path) | ||||||
|       if ([string]::IsNullOrWhiteSpace($Path)) { return $null } |       if ([string]::IsNullOrWhiteSpace($Path)) { return $null } | ||||||
|       if ($Path -like "\\*") { return ($Path -split '\\')[2] } |       if ($Path -like "\\*") { return ($Path -split '\\')[2] } | ||||||
|       return $null |       return $null | ||||||
| } |     } | ||||||
| function Get-Max3 { |     function Get-Max3 { | ||||||
|       param([int[]]$Values) |       param([int[]]$Values) | ||||||
|       if (-not $Values) { return 0 } |       if (-not $Values) { return 0 } | ||||||
|       return (($Values | Measure-Object -Maximum).Maximum) |       return (($Values | Measure-Object -Maximum).Maximum) | ||||||
| } |     } | ||||||
|  |  | ||||||
| # Build: GroupName (lower) -> memberships[] |     # Build: GroupName (lower) -> memberships[] | ||||||
| $allGroups = Get-DfsReplicationGroup -ErrorAction SilentlyContinue |     $allGroups = Get-DfsReplicationGroup -ErrorAction SilentlyContinue | ||||||
| $groupMembershipMap = @{} |     $groupMembershipMap = @{} | ||||||
| foreach ($g in $allGroups) { |     foreach ($g in $allGroups) { | ||||||
|       $ms = Get-DfsrMembership -GroupName $g.GroupName -ErrorAction SilentlyContinue |       $ms = Get-DfsrMembership -GroupName $g.GroupName -ErrorAction SilentlyContinue | ||||||
|       $groupMembershipMap[$g.GroupName.ToLower()] = $ms |       $groupMembershipMap[$g.GroupName.ToLower()] = $ms | ||||||
| } |     } | ||||||
|  |  | ||||||
| # Flatten all memberships for regex fallback |     # Flatten all memberships for regex fallback | ||||||
| $allMemberships = @() |     $allMemberships = @() | ||||||
| foreach ($arr in $groupMembershipMap.Values) { if ($arr) { $allMemberships += $arr } } |     foreach ($arr in $groupMembershipMap.Values) { if ($arr) { $allMemberships += $arr } } | ||||||
|  |  | ||||||
| $rows = New-Object System.Collections.Generic.List[psobject] |     $rows = New-Object System.Collections.Generic.List[psobject] | ||||||
|  |  | ||||||
| # Enumerate namespace roots |     # Enumerate namespace roots | ||||||
| $roots = Get-DfsnRoot -ErrorAction Stop | Where-Object { $_.Path -like "$DomainPrefix\*" } |     $roots = Get-DfsnRoot -ErrorAction Stop | Where-Object { $_.Path -like "$DomainPrefix\*" } | ||||||
|  |  | ||||||
| Write-Host "DFS Namespace and Replication Overview" -ForegroundColor Cyan |     Write-Host "DFS Namespace and Replication Overview" -ForegroundColor Cyan | ||||||
| Write-Host "------------------------------------------------------`n" |     Write-Host "------------------------------------------------------`n" | ||||||
|  |  | ||||||
| foreach ($root in $roots) { |     foreach ($root in $roots) { | ||||||
|  |  | ||||||
|       $rootPath  = $root.Path |       $rootPath  = $root.Path | ||||||
|       $rootLeaf  = ($rootPath -split '\\')[-1] |       $rootLeaf  = ($rootPath -split '\\')[-1] | ||||||
| @@ -242,12 +247,10 @@ foreach ($root in $roots) { | |||||||
|           $rows.Add($row) | Out-Null |           $rows.Add($row) | Out-Null | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| } |     } | ||||||
|  |  | ||||||
| # Render as a PowerShell table (multi-line cells wrap) |     # Render as a PowerShell bordered grid with one-space left/right padding in every cell | ||||||
| #$rows | Format-Table -AutoSize -Wrap |     function Write-DfsGrid { | ||||||
|  |  | ||||||
| function Write-DfsGrid { |  | ||||||
|       [CmdletBinding()] |       [CmdletBinding()] | ||||||
|       param( |       param( | ||||||
|         [Parameter(Mandatory)] |         [Parameter(Mandatory)] | ||||||
| @@ -255,8 +258,8 @@ function Write-DfsGrid { | |||||||
|  |  | ||||||
|         [string[]]$Columns = @('Namespace','Member Folder Target(s)','Replication Locations','Namespace Servers'), |         [string[]]$Columns = @('Namespace','Member Folder Target(s)','Replication Locations','Namespace Servers'), | ||||||
|  |  | ||||||
|     # Reasonable max widths; tune to your console |         # Reasonable max widths; tune to your console (these are content+padding widths) | ||||||
|     [int[]]$MaxWidths = @(50, 60, 50, 28), |         [int[]]$MaxWidths = @(70, 70, 52, 30), | ||||||
|  |  | ||||||
|         [switch]$Ascii  # use +-| instead of box-drawing if your console garbles Unicode |         [switch]$Ascii  # use +-| instead of box-drawing if your console garbles Unicode | ||||||
|       ) |       ) | ||||||
| @@ -286,9 +289,8 @@ function Write-DfsGrid { | |||||||
|         return ($s.Substring(0, $w-1) + '…') |         return ($s.Substring(0, $w-1) + '…') | ||||||
|       } |       } | ||||||
|  |  | ||||||
|   # Materialize and compute widths |       # Materialize and compute widths (include one-space left/right padding for header and data) | ||||||
|       $rows = @($Data | ForEach-Object { |       $rows = @($Data | ForEach-Object { | ||||||
|     # Build a string-only hashtable per row for consistent measurement |  | ||||||
|         $o = @{} |         $o = @{} | ||||||
|         foreach ($c in $Columns) { $o[$c] = [string]($_.$c) } |         foreach ($c in $Columns) { $o[$c] = [string]($_.$c) } | ||||||
|         [pscustomobject]$o |         [pscustomobject]$o | ||||||
| @@ -297,9 +299,10 @@ function Write-DfsGrid { | |||||||
|       $widths = @() |       $widths = @() | ||||||
|       for ($i=0; $i -lt $Columns.Count; $i++) { |       for ($i=0; $i -lt $Columns.Count; $i++) { | ||||||
|         $col = $Columns[$i] |         $col = $Columns[$i] | ||||||
|     $max = $col.Length |         # Start with header length including padding | ||||||
|  |         $max = (" " + $col + " ").Length | ||||||
|         foreach ($r in $rows) { |         foreach ($r in $rows) { | ||||||
|       $len = ([string]$r.$col).Length |           $len = (" " + [string]$r.$col + " ").Length | ||||||
|           if ($len -gt $max) { $max = $len } |           if ($len -gt $max) { $max = $len } | ||||||
|         } |         } | ||||||
|         $widths += [Math]::Min($max, $MaxWidths[$i]) |         $widths += [Math]::Min($max, $MaxWidths[$i]) | ||||||
| @@ -318,10 +321,10 @@ function Write-DfsGrid { | |||||||
|           } |           } | ||||||
|           $line |           $line | ||||||
|       } |       } | ||||||
|   function DrawMid() { |       function DrawMid([string[]]$Columns, [int[]]$widths, $H) { | ||||||
|         $line = $H.vt |         $line = $H.vt | ||||||
|         for ($i=0; $i -lt $widths.Count; $i++) { |         for ($i=0; $i -lt $widths.Count; $i++) { | ||||||
|       $line += TruncPad $Columns[$i] $widths[$i] |           $line += TruncPad (" " + $Columns[$i] + " ") $widths[$i] | ||||||
|           $line += $H.vt |           $line += $H.vt | ||||||
|         } |         } | ||||||
|         $line |         $line | ||||||
| @@ -354,11 +357,11 @@ function Write-DfsGrid { | |||||||
|           } |           } | ||||||
|           $line |           $line | ||||||
|       } |       } | ||||||
|   function DrawRow($r) { |       function DrawRow($r, [string[]]$Columns, [int[]]$widths, $H) { | ||||||
|         $line = $H.vt |         $line = $H.vt | ||||||
|         for ($i=0; $i -lt $widths.Count; $i++) { |         for ($i=0; $i -lt $widths.Count; $i++) { | ||||||
|           $val = [string]$r.($Columns[$i]) |           $val = [string]$r.($Columns[$i]) | ||||||
|       $line += TruncPad $val $widths[$i] |           $line += TruncPad (" " + $val + " ") $widths[$i] | ||||||
|           $line += $H.vt |           $line += $H.vt | ||||||
|         } |         } | ||||||
|         $line |         $line | ||||||
| @@ -366,21 +369,21 @@ function Write-DfsGrid { | |||||||
|  |  | ||||||
|       # Render with group separators between namespaces (when the Namespace cell is non-empty) |       # Render with group separators between namespaces (when the Namespace cell is non-empty) | ||||||
|       Write-Host (DrawTop) |       Write-Host (DrawTop) | ||||||
|   Write-Host (DrawMid) |       Write-Host (DrawMid -Columns $Columns -widths $widths -H $H) | ||||||
|       Write-Host (DrawHeaderSep) |       Write-Host (DrawHeaderSep) | ||||||
|  |  | ||||||
|       $first = $true |       $first = $true | ||||||
|       foreach ($r in $rows) { |       foreach ($r in $rows) { | ||||||
|         if (-not $first -and ([string]$r.$($Columns[0])) ) { |         if (-not $first -and ([string]$r.$($Columns[0])) ) { | ||||||
|       # Namespace changed → draw a heavy-ish separator |           # Namespace changed → draw a separator | ||||||
|           Write-Host (DrawSep) |           Write-Host (DrawSep) | ||||||
|         } |         } | ||||||
|         $first = $false |         $first = $false | ||||||
|     Write-Host (DrawRow $r) |         Write-Host (DrawRow -r $r -Columns $Columns -widths $widths -H $H) | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       Write-Host (DrawBottom) |       Write-Host (DrawBottom) | ||||||
| } |     } | ||||||
|  |  | ||||||
| Write-DfsGrid -Data $rows |     Write-DfsGrid -Data $rows | ||||||
| ``` |     ``` | ||||||
		Reference in New Issue
	
	Block a user