-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDownload-SupervisorContent.ps1
More file actions
63 lines (52 loc) · 2.42 KB
/
Download-SupervisorContent.ps1
File metadata and controls
63 lines (52 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Fixed: Download-SupervisorContent.ps1
# https://techdocs.broadcom.com/us/en/vmware-cis/vcf/vcf-9-0-and-later/9-0/vsphere-supervisor-installation-and-configuration/updating-vsphere-supervisor/updating-the-vsphere-with-tanzu-environment/configuring-a-subscribed-content-library-for-supervisor-images-in-air-gapped-environment/create-a-remote-content-library-pulisher-in-a-local-environment.html
# Set-ExecutionPolicy RemoteSigned -Scope Process
param (
[string]$BaseUrl = "https://wp-content-pstg.broadcom.com/supervisor/v1/latest/",
[string]$DownloadPath = ".\SupervisorContent"
)
function Get-FilesFromHtml {
param ([string]$url)
try {
$html = Invoke-WebRequest -Uri $url -UseBasicParsing
$links = $html.Links | Where-Object { $_.href -ne "../" }
foreach ($link in $links) {
$href = $link.href
$childUrl = "$url$href"
$relativePath = ($childUrl -replace [regex]::Escape($BaseUrl), "").Replace('/', '\')
$localPath = Join-Path $DownloadPath $relativePath
if ($href -match "/$") {
# It's a folder
if (-not (Test-Path $localPath)) {
New-Item -ItemType Directory -Path $localPath -Force | Out-Null
}
Get-FilesFromHtml -url $childUrl
} else {
# It's a file
$localDir = Split-Path $localPath -Parent
if (-not (Test-Path $localDir)) {
New-Item -ItemType Directory -Path $localDir -Force | Out-Null
}
if (Test-Path $localPath) {
Write-Host "Skipping (already exists): $relativePath" -ForegroundColor Yellow
continue
}
Write-Host "Downloading: $childUrl" -ForegroundColor Cyan
Invoke-WebRequest -Uri $childUrl -OutFile $localPath -UseBasicParsing
}
}
} catch {
Write-Warning "Failed to process $url : $($_.Exception.Message)"
}
}
# Ensure download path is set
if ([string]::IsNullOrEmpty($DownloadPath)) {
throw "DownloadPath must be specified."
}
# Create base folder if missing
if (-not (Test-Path $DownloadPath)) {
New-Item -ItemType Directory -Path $DownloadPath -Force | Out-Null
}
# Start the recursive download
Get-FilesFromHtml -url $BaseUrl
Write-Host "`n✅ Finished downloading all Supervisor image content." -ForegroundColor Green