Skip to content

Instantly share code, notes, and snippets.

@nicholasdille
Created January 5, 2015 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasdille/bf76ad4e9e31c1794a79 to your computer and use it in GitHub Desktop.
Save nicholasdille/bf76ad4e9e31c1794a79 to your computer and use it in GitHub Desktop.
Download Script for all #PSDSC Resources on TechNet
param(
[string]$ResourceUrlCacheFile = (Join-Path -Path $PSScriptRoot -ChildPath 'PSDSC-ResourceDownloader.clixml')
,
[switch]$IgnoreCachedUrls = $false
,
[switch]$OverwriteExistingModules = $false
)
if (-Not (Test-Path -Path $ResourceUrlCacheFile) -Or $IgnoreCachedUrls) {
$ModuleList = New-Object System.Collections.ArrayList
$PageList = New-Object System.Collections.Stack
$PageList.Push('https://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=Tag&f%5B0%5D.Value=Windows%20PowerShell%20Desired%20State%20Configuration&f%5B0%5D.Text=Windows%20PowerShell%20Desired%20State%20Configuration&pageIndex=1')
$PageBeenThere = New-Object System.Collections.ArrayList
while ($PageList.Count -gt 0) {
$url = $PageList.Pop()
if (-Not $PageBeenThere.Contains($url)) {
#'processing {0}' -f $url
$PageBeenThere.Add($url) | Out-Null
$page = Invoke-WebRequest $url
$page.Links | where {$_.href -match 'pageIndex' -and $_.innerText -match '\d+'} | foreach {
$url = $_.href
$url = $url.Replace('about:', 'https://gallery.technet.microsoft.com')
$url = $url.Replace('&', '&')
if (-Not $PageBeenThere.Contains($url)) {
$PageList.Push($url)
}
}
$page.Links | where {$_.href -match '^about:/scriptcenter/(.+)-[a-z0-9]{8}$'} | foreach {
$url = $_.href
$url = $url.Replace('about:', 'https://gallery.technet.microsoft.com')
$url = $url.Replace('&', '&')
$ModuleList.Push($url)
}
Start-Sleep -Seconds 5
}
}
$ModuleList | Export-Clixml -Path $ResourceUrlCacheFile
} else {
$ModuleList = Import-Clixml -Path $ResourceUrlCacheFile
}
Foreach ($ModuleUrl in $ModuleList) {
$page = Invoke-WebRequest $ModuleUrl
$page.Links | where {$_.href -match '^about:/scriptcenter/(.+-[a-z0-9]{8})/file/'} | select -First 1 | foreach {
$ItemName = $Matches[1]
$url = $_.href
$url = $url.Replace('about:', 'https://gallery.technet.microsoft.com')
$url = $url.Replace('&', '&')
$url -match '/([^/]+.zip$)' | Out-Null
$FileName = $Matches[1]
$FileName = (Join-Path -Path $PSScriptRoot -ChildPath ('\DSC-Modules\' + $FileName))
if (-Not (Test-Path -Path $FileName) -Or $OverwriteExistingModules) {
Invoke-WebRequest $url -OutFile $FileName
}
}
}
@nicholasdille
Copy link
Author

This gist has been moved to my function library in repository psdsc(https://github.com/nicholasdille/psdsc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment