Guest User

Untitled

a guest
Jul 20th, 2025
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 4.69 KB | Software | 0 0
  1. # URL of Adobe's app version page
  2. $url = "https://helpx.adobe.com/uk/enterprise/kb/adobe-cc-app-base-versions.html"
  3.  
  4. # Download the full HTML content using curl
  5. Write-Host "Fetching live HTML from Adobe..."
  6. $html = curl $url | Out-String
  7. Write-Host "Downloaded $($html.Length) characters.`n"
  8.  
  9. # Find the section where version tables begin
  10. $marker = "Current base versions of apps (version N)"
  11. $markerIndex = $html.IndexOf($marker)
  12. if ($markerIndex -lt 0) { throw "Marker text not found." }
  13.  
  14. # Extract only the HTML after the marker to limit scope
  15. $htmlAfterMarker = $html.Substring($markerIndex)
  16.  
  17. # Identify and extract all <table> blocks after the marker
  18. $tableMatches = [regex]::Matches($htmlAfterMarker, "(?is)<table.*?>.*?</table>")
  19. $tableHtmls = $tableMatches | ForEach-Object { $_.Value }
  20. Write-Host "Found $($tableHtmls.Count) tables after marker.`n"
  21.  
  22. # Parse a single HTML table into a list of PSObjects
  23. function Convert-TableHtml {
  24.     param ([string]$tableHtml)
  25.  
  26.     # Removes HTML tags and non-printable characters from cell content
  27.     function StripHtml {
  28.         param($text)
  29.         $clean = $text -replace "<.*?>", ""
  30.         $asciiOnly = [System.Text.RegularExpressions.Regex]::Replace($clean, "[^\u0020-\u007E]", " ")
  31.         return ($asciiOnly -replace "\s+", " ").Trim()
  32.     }
  33.  
  34.     # Extract rows from <tr> tags
  35.     $rows = [regex]::Matches($tableHtml, "(?is)<tr[^>]*>.*?</tr>")
  36.     if ($rows.Count -eq 0) { return @() }
  37.  
  38.     # Clean and normalize header cells from first row
  39.     $headerCells = [regex]::Matches($rows[0].Value, "(?is)<t[dh][^>]*>(.*?)</t[dh]>")
  40.     $headers = $headerCells | ForEach-Object { StripHtml $_.Groups[1].Value }
  41.  
  42.     # Parse each remaining row and map data to headers
  43.     $rows = $rows[1..($rows.Count - 1)]
  44.     $data = @()
  45.     foreach ($row in $rows) {
  46.         $cells = [regex]::Matches($row.Value, "(?is)<td[^>]*>(.*?)</td>") | ForEach-Object { StripHtml $_.Groups[1].Value }
  47.         $obj = [ordered]@{}
  48.         for ($i = 0; $i -lt $headers.Count; $i++) {
  49.             $obj[$headers[$i]] = if ($i -lt $cells.Count) { $cells[$i] } else { "" }
  50.         }
  51.         $data += New-Object PSObject -Property $obj
  52.     }
  53.  
  54.     return $data
  55. }
  56.  
  57. # Parse and sort Current Versions table
  58. $currentRaw = Convert-TableHtml $tableHtmls[0]
  59.  
  60. # Sort Current Versions: Sap Code ascending, Base version descending
  61. $currentSorted = $currentRaw | Sort-Object `
  62.     @{ Expression = { $_.'Sap Code' }; Descending = $false },
  63.     @{ Expression = {
  64.         # Pad each segment of version number for accurate descending sort
  65.         $ver = ($_.'Base version' -replace "[^\d\.]", "") -split "\."
  66.         ($ver | ForEach-Object { "{0:D4}" -f ($_ -as [int]) }) -join "."
  67.     }; Descending = $true }
  68.  
  69. Write-Host "`n=== Current Base Versions (Sorted) ==="
  70. $currentSorted | Format-Table -AutoSize
  71.  
  72. # Parse and combine all Previous Versions tables
  73. $previousTableHtmls = $tableHtmls[1..($tableHtmls.Count - 1)]
  74. $previousVersions = @()
  75. foreach ($htmlBlock in $previousTableHtmls) {
  76.     $previousVersions += Convert-TableHtml $htmlBlock
  77. }
  78.  
  79. # Build a set of known current Sap Code + Base version combos
  80. $currentPairs = $currentSorted | ForEach-Object {
  81.     "$($_.'Sap Code')|$($_.'Base version')"
  82. }
  83.  
  84. # Remove any Previous Versions rows that match a Current Version
  85. $filteredPrevious = $previousVersions | Where-Object {
  86.     "$($_.'Sap Code')|$($_.'Base version')" -notin $currentPairs
  87. }
  88.  
  89. # Deduplicate repeated Sap Code + Base version entries
  90. # For each group, retain the row with the longest Platform IDs string
  91. $deduplicatedPrevious = $filteredPrevious | Group-Object {
  92.     "$($_.'Sap Code')|$($_.'Base version')"
  93. } | ForEach-Object {
  94.     $_.Group | Sort-Object {
  95.         ($_. 'Platform IDs for applicable platforms' ).Length
  96.     } -Descending | Select-Object -First 1
  97. }
  98.  
  99. # Final sort: Sap Code asc, Base version desc
  100. $sortedPrevious = $deduplicatedPrevious | Sort-Object `
  101.     @{ Expression = { $_.'Sap Code' }; Descending = $false },
  102.     @{ Expression = {
  103.         $ver = ($_.'Base version' -replace "[^\d\.]", "") -split "\."
  104.         ($ver | ForEach-Object { "{0:D4}" -f ($_ -as [int]) }) -join "."
  105.     }; Descending = $true }
  106.  
  107. # Display cleaned, deduplicated previous versions table
  108. Write-Host "`n=== All Previous Versions (Deduplicated, Sorted) ==="
  109. $sortedPrevious | Format-Table -AutoSize
  110.  
  111. # Combine Sap Code and Base version into command-line format
  112. $versionPairs = $sortedPrevious | ForEach-Object {
  113.     "$($_.'Sap Code')#$($_.'Base version')"
  114. }
  115.  
  116. # Output ready-to-run uninstaller command
  117. $summaryString = "AdobeUninstaller.exe --products=" + ($versionPairs -join ",") + " --skipNotInstalled"
  118. Write-Host "`n=== Adobe Uninstaller Command ==="
  119. Write-Host $summaryString
Advertisement
Add Comment
Please, Sign In to add comment