I got tired of checking and downloading new versions of the Orion SDK from GitHub. OK, so I didn't exactly get tired of it, but I decided to have my computer do this for me. So how best to do it? PowerShell of course!
$TargetDirectory = "C:\Place\I\Want\To\Save\The\Downloads"
$DownloadBetas = $true
$DownloadLatestOnly = $false$SdkPage = Invoke-WebRequest -Uri "https://github.com/solarwinds/OrionSDK/releases"
$Links = $SdkPage.Links | Where-Object { $_.innerText -like "*OrionSDK.msi*" }
$Links | Add-Member -MemberType ScriptProperty -Name IsBeta -Value { $this.href.Split("/")[-2] -like "*-beta" } -Force
$Links | Add-Member -MemberType ScriptProperty -Name Version -Value { if ( $this.IsBeta ) { [Version]( $this.href.Replace("v", "").Replace("-beta", "").Split("/")[-2] ) } else { [version]( $this.href.Replace("v", "").Split("/")[-2] ) } } -Force
$Links | Add-Member -MemberType ScriptProperty -Name Url -Value { "https://github.com$( $this.href )" } -Force
$Links | Add-Member -MemberType ScriptProperty -Name FileName -Value { "OrionSDK_$( $this.Version )$( if ( $this.IsBeta ) { "-beta" } ).msi" }
if ( $DownloadLatestOnly -and $DownloadBetas )
{
$DownloadLinks = $Links | Sort-Object -Property Version -Descending | Select-Object -First 1
}
elseif ( $DownloadLatestOnly -and -not $DownloadBetas )
{
$DownloadLinks = $Links | Where-Object { -not $_.IsBeta } | Sort-Object -Property Version -Descending | Select-Object -First 1
}
elseif ( -not $DownloadLatestOnly -and -not $DownloadBetas )
{
$DownloadLinks = $Links | Where-Object { -not $_.IsBeta }
}
else # ( -not $DownloadLatestOnly -and $DownloadBetas )
{
$DownloadLinks = $Links
}
$DownloadLinks | ForEach-Object { Invoke-WebRequest -Uri $_.Url -OutFile ( Join-Path -Path $TargetDirectory -ChildPath $_.FileName ) }
This does a few things:
1) Gets all of the MSI Downloads from the above page.
2) Adds the IsBeta and the Version members to the link objects
3) Filters (depending on the DownloadBetas and DownloadLatestOnly flags)
4) Download them.