msfreaks / EvergreenAdmx

Script to keep Admx files up-to-date.
MIT License
108 stars 14 forks source link

Get-FSLogixOnline not working #5

Closed severud closed 2 years ago

severud commented 2 years ago

I modified the code to get the current version and redirected path from aka.ms/fslogix/download as follows:


function Get-FSLogixOnline {

    <#     .SYNOPSIS
    Returns latest Version and Uri for FSLogix
   #>
    Function Get-RedirectedUrl {
        Param (
            [Parameter(Mandatory = $true)]
            [String]$url
        )

        $request = [System.Net.WebRequest]::Create($url)
        $request.AllowAutoRedirect = $true

        try {
            $response = $request.GetResponse()
            $response.ResponseUri.AbsoluteUri
            $response.Close()
        }

        catch {
            "ERROR: $_"
        }

    }

    try {
        $ProgressPreference = 'SilentlyContinue'
        $url = Get-RedirectedUrl -URL 'https://aka.ms/fslogix/download'
        # grab version
        $Version = ($url.Split("/")[-1] | Select-String -Pattern "(\d+(\.\d+){1,4})" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }).ToString()

        # return evergreen object
        return @{ Version = $Version; URI = $url }
    }
    catch {
        Throw $_
    }
}
    Function Get-RedirectedUrl {
        Param (
            [Parameter(Mandatory = $true)]
            [String]$url
        )

        $request = [System.Net.WebRequest]::Create($url)
        $request.AllowAutoRedirect = $true

        try {
            $response = $request.GetResponse()
            $response.ResponseUri.AbsoluteUri
            $response.Close()
        }

        catch {
            "ERROR: $_"
        }

    }

    try {
        $ProgressPreference = 'SilentlyContinue'
        $url = Get-RedirectedUrl -URL 'https://aka.ms/fslogix/download'
        # grab version
        $Version = ($url.Split("/")[-1] | Select-String -Pattern "(\d+(\.\d+){1,4})" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }).ToString()

        # return evergreen object
        return @{ Version = $Version; URI = $url }
    }
    catch {
        Throw $_
    }
}
msfreaks commented 2 years ago

Thanks! More robust way to get a redirected Url.

msfreaks commented 2 years ago

Fixed in 2107.1