msfreaks / EvergreenAdmx

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

PreferLocalOneDrive parameter does not work #14

Closed JonathanPitre closed 2 years ago

JonathanPitre commented 2 years ago

It would be a good idea to uninstall OneDrive once the ADMX files were copied.

JonathanPitre commented 2 years ago

You can have a look here to get inspired

https://github.com/JonathanPitre/Scripts/blob/master/Update-PolicyDefinitions/Update-PolicyDefinitions.ps1

msfreaks commented 2 years ago

Hi Jonathan,

VERBOSE: Processing Admx files for Microsoft OneDrive VERBOSE: GET https://go.microsoft.com/fwlink/p/?LinkID=844652 with 0-byte payload VERBOSE: received 0-byte response of content type VERBOSE: Found new version 22.111.0522.0002 for 'Microsoft OneDrive' VERBOSE: Downloading 'https://oneclient.sfx.ms/Win/Prod/22.111.0522.0002/amd64/OneDriveSetup.exe' to 'C:\install\admx\work\\downloads\OneDriveSetup.exe' VERBOSE: GET https://oneclient.sfx.ms/Win/Prod/22.111.0522.0002/amd64/OneDriveSetup.exe with 0-byte payload VERBOSE: received 55847320-byte response of content type application/octet-stream VERBOSE: Installing downloaded OneDrive installer VERBOSE: Grabbing uninstallation info from registry for OneDrive installer VERBOSE: Found 'Microsoft OneDrive' VERBOSE: Grabbing installation path for OneDrive installer VERBOSE: Found 'C:\Program Files\Microsoft OneDrive\22.111.0522.0002_1' VERBOSE: Copying Admx files from 'C:\Program Files\Microsoft OneDrive\22.111.0522.0002_1\adm' to 'C:\install\admx\work\\admx\Microsoft OneDrive' VERBOSE: Copying Admx files from 'C:\Program Files\Microsoft OneDrive\22.111.0522.0002_1\adm' to 'C:\install\admx\store\' VERBOSE: Uninstalling OneDrive installer

For me, it uninstalls right after copying the admx files. But only if "PreferLocalOneDrive" is false, and OneDrive is not yet installed. If OneDrive is already installed, the script does not uninstall OneDrive.

Can you run it with -Verbose and show your output?

JonathanPitre commented 2 years ago

When I use the flag "PreferLocalOneDrive $False" nothing happens, no command is being run.

However, I have not seen any issues with OneDrive installation so far with the latest version.

JonathanPitre commented 2 years ago

The parameter -PreferLocalOneDrive does not work, it does not copy the OneDrive.admx to the central policy store

JonathanPitre commented 2 years ago

The function Get-OneDriveOnline did not check for the x64 install folder.

Here's the fix:

function Get-OneDriveOnline {
<#
    .SYNOPSIS
    Returns latest Version and Uri for OneDrive
#>
    param (
        [bool]$PreferLocalOneDrive
    )

    if ($PreferLocalOneDrive) {

        if (Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\OneDrive" -ErrorAction SilentlyContinue) {
            $URI = "$((Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\OneDrive").CurrentVersionPath)"
            $Version = "$((Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\OneDrive").Version)"
        }
        if ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\OneDrive" -ErrorAction SilentlyContinue)) {
            $URI = "$((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\OneDrive").CurrentVersionPath)"
            $Version = "$((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\OneDrive").Version)"
        }

        return @{ Version = $Version; URI = $URI }
    } else {
        try {
            $ProgressPreference = 'SilentlyContinue'
            $url = "https://go.microsoft.com/fwlink/p/?LinkID=844652"
            # grab content without redirecting to the download
            $web = Invoke-WebRequest -UseDefaultCredentials -Uri $url -UseBasicParsing -MaximumRedirection 0 -ErrorAction Ignore
            # grab uri
            $URI = $web.Headers.Location
            # grab version
            $Version = ($URI | Select-String -Pattern "(\d+(\.\d+){1,4})" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }).ToString()

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

Hi Jonathan,

I added your fix in the DEV branch. Can you see if that works for you?

JonathanPitre commented 2 years ago

yep it works