$root = 'E:\Sync Method\Corporate\Zefiro Methane Corp. - Documents' $outputDirectory = 'C:\Users\MattSpeer\OneDrive - Add Source Group\Documents\1- Projects\Zefiro - Data Migration' $textFile = Join-Path $outputDirectory 'Zefiro-Methane-Corp-Documents-tree.txt' $htmlFile = Join-Path $outputDirectory 'Zefiro-Methane-Corp-Documents-tree.html' if (-not (Test-Path -LiteralPath $root -PathType Container)) { throw "Folder not found: $root" } New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null $script:textLines = [System.Collections.Generic.List[string]]::new() $script:html = [System.Text.StringBuilder]::new() $script:scanErrors = 0 function ConvertTo-HtmlEncoded { param([string]$Text) return [System.Net.WebUtility]::HtmlEncode($Text) } function Add-TreeItems { param( [string]$Path, [string]$Prefix ) try { $items = @( Get-ChildItem -LiteralPath $Path -Force -ErrorAction Stop | Sort-Object @{ Expression = { if ($_.PSIsContainer) { 0 } else { 1 } } }, Name ) } catch { $script:scanErrors++ [void]$script:textLines.Add("$Prefix[Unable to read: $($_.Exception.Message)]") [void]$script:html.AppendLine( "
  • Unable to read: $(ConvertTo-HtmlEncoded $_.Exception.Message)
  • " ) return } for ($index = 0; $index -lt $items.Count; $index++) { $item = $items[$index] $isLast = $index -eq ($items.Count - 1) $connector = if ($isLast) { '\-- ' } else { '|-- ' } $nextPrefix = $Prefix + $(if ($isLast) { ' ' } else { '| ' }) $nameHtml = ConvertTo-HtmlEncoded $item.Name $pathHtml = ConvertTo-HtmlEncoded $item.FullName $isLink = -not [string]::IsNullOrWhiteSpace([string]$item.LinkType) if ($item.PSIsContainer -and -not $isLink) { [void]$script:textLines.Add("$Prefix$connector$($item.Name)") [void]$script:html.AppendLine( "
  • 📁 $nameHtml
  • ') } elseif ($item.PSIsContainer -and $isLink) { $target = @($item.Target) -join ', ' [void]$script:textLines.Add( "$Prefix$connector$($item.Name) [Link → $target]" ) [void]$script:html.AppendLine( "" ) } else { [void]$script:textLines.Add("$Prefix$connector$($item.Name)") [void]$script:html.AppendLine( "
  • 📄 $nameHtml
  • " ) } } } $rootNameHtml = ConvertTo-HtmlEncoded (Split-Path -Path $root -Leaf) $rootPathHtml = ConvertTo-HtmlEncoded $root $generated = Get-Date -Format 'yyyy-MM-dd HH:mm:ss' [void]$script:textLines.Add($root) [void]$script:html.AppendLine(@" Team Site Documents Directory

    Team Site – Documents

    Generated $generated
    Root: $rootPathHtml
    "@) $script:textLines | Set-Content -LiteralPath $textFile -Encoding UTF8 $script:html.ToString() | Set-Content -LiteralPath $htmlFile -Encoding UTF8 Write-Host "Text report: $textFile" Write-Host "HTML report: $htmlFile" Write-Host "Unreadable folders: $script:scanErrors" Start-Process $htmlFile