Created
December 15, 2021 09:51
-
-
Save claw0ry/591fbce7484c59a5aa8f016e2b371860 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-MIDServerDownloadUrl { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory = $true)] | |
| [string[]] | |
| $InstanceName, | |
| [Parameter()] | |
| [ValidateSet("windows", "linux")] | |
| [string] | |
| $OperatingSystem = "windows", | |
| [Parameter()] | |
| [ValidateSet("msi", "zip")] | |
| [string] | |
| $Type = "msi" | |
| ) | |
| begin { | |
| $InstanceName = $InstanceName | ForEach-Object { $_.ToLower() } | |
| if ($Type -eq "msi") { | |
| $FilePrefix = "mid-windows-installer" | |
| $BaseURL = "https://install.service-now.com/glide/distribution/builds/package/app-signed/mid-windows-installer" | |
| } else { | |
| $FilePrefix = "mid" | |
| $BaseURL = "https://install.service-now.com/glide/distribution/builds/package/mid" | |
| } | |
| } | |
| process { | |
| foreach ($Instance in $InstanceName) { | |
| $InstanceStats = Invoke-WebRequest -Uri "https://$($Instance).service-now.com/stats.do" | |
| $BuildDate = $InstanceStats.Content | Select-String -Pattern 'Build date: ([^<]{1,})' | |
| $BuildDate = ($BuildDate.Matches.Value -split ": ")[1] | |
| $BuildStamp = $InstanceStats.Content | Select-String -Pattern "MID buildstamp: ([^<]{1,})" | |
| $BuildStamp = ($BuildStamp.Matches.Value -split ": ")[1] | |
| $BuildYear = $BuildDate.Split("_")[0].Split("-")[2] | |
| $BuildMonth = $BuildDate.Split("_")[0].Split("-")[0] | |
| $BuildDay = $BuildDate.Split("_")[0].Split("-")[1] | |
| $DirectDowloadURL = "{0}/{1}/{2}/{3}/{4}.{5}.{6}.x86-64.{7}" -f ( | |
| $BaseURL, | |
| $BuildYear, | |
| $BuildMonth, | |
| $BuildDay, | |
| $FilePrefix, | |
| $BuildStamp, | |
| $OperatingSystem, | |
| $Type | |
| ) | |
| $DirectDowloadURL | |
| } | |
| } | |
| end {} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment