Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2017 17:40
Show Gist options
  • Save anonymous/d8346b378166a5dad2c9d52a8fdf3b77 to your computer and use it in GitHub Desktop.
Save anonymous/d8346b378166a5dad2c9d52a8fdf3b77 to your computer and use it in GitHub Desktop.
function GetData {
Param (
[Parameter(Mandatory=$true)][int]$MajorVersion,
[Parameter(Mandatory=$true)][int]$MinorVersion,
[Parameter(Mandatory=$true)][string]$Find
)
Process{
Try{
$cdnBaseURI = "https://example.com"
$versions = @(
("Major", "Minor", "wcPatchURI" ),
(6, 0, "$($cdnBaseURI)/WS2008.msu" ),
(6, 1, "$($cdnBaseURI)/WS2008R2.msu" ),
(6, 2, "$($cdnBaseURI)/WS2012.msu" ),
(6, 3, "$($cdnBaseURI)/WS2012R2.msu" ),
(10, 0, "$($cdnBaseURI)/WS2016.msu" )
)
$parentIteration = 0
$requestedIndex = $()
$found = $false
ForEach ($version in $versions) {
$childIteration = 0
ForEach ($item in $version) {
If ($Find -eq $item -And $found -eq $false){
$requestedIndex = $($parentIteration, $childIteration)
$found = $true
}
If ($found) {
Break
}
$childIteration++
}
If ($found) {
Break
}
$parentIteration++
}
ForEach ($version in $versions){
If ($version[0] -eq $MajorVersion -And $version[1] -eq $MinorVersion){
$request = $(
$version[$requestedIndex[1]],
($requestedIndex[0], $requestedIndex[1])
)
Break
}
}
return $request
}
Catch {
Write-Host "Oops?"
Exit
}
}
}
$osvmaj = ([environment]::OSVersion.Version).Major
$osvmin = ([environment]::OSVersion.Version).Minor
$r = GetData -MajorVersion $osvmaj -MinorVersion $osvmin -Find "wcPatchURI"
Write-Host "Value of request: $($r[0])"
Write-Host "Index of request: [$($r[1][0])][$($r[1][1])]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment