Trouble with auto update powershell script

76 views
Skip to first unread message

Kris Mackey

unread,
Mar 21, 2024, 5:53:58 PM3/21/24
to GAM for Google Workspace
Hello,

Hoping to get some help or feedback into an issue I am having. I created the PowerShell script file using the outline from another chain in this group. It worked well for me on more than one occasion, a few months back, but now has started to return an error. 

Below is what I am seeing when I run this script in PS. 

PS C:\GAMADV-XTD3> ./updateGAMADV-XTD3.ps1
WARNING: Config File: C:\Users\userName\.gam\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\Users\userName\.gam\oauth2.txt, Not Found
WARNING: Config File: C:\Users\userName\.gam\gam.cfg, Section: DEFAULT, Item: oauth2service_json, Value: C:\Users\userName\.gam\oauth2service.json, Not Found
GAMADV-XTD3 is already up-to-date

I have since manually updated by running the .msi file from the downloads page. Just hoping to get this functionality back since it was super helpful. The referenced files are housed in C:\GAMADV-XTD3 but for some reason the script is checking in another location. I ran the "gam config verify" command and the references there appear to point to the correct location. 


Possible related, I also ran the "gam version checkrc" command before and after the manual update. For some reason the "latest version" is stuck at this older version. The "current version" changed post manual update. Post example below: 

c:\GAMWork>gam version checkrc
GAMADV-XTD3 6.71.18 - https://github.com/taers232c/GAMADV-XTD3 - pyinstaller
Ross Scroggs <rem...@gmail.com>
Python 3.12.2 64-bit final
Windows 10 10.0.19045 SP0 Multiprocessor Free AMD64
Path: C:\GAMADV-XTD3
Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, customer_id: my_customer, domain:
Time: 2024-03-21T20:32:00+00:00
Version Check:
  Current: 6.71.18
   Latest: 6.17.18


Thanks everyone!


This Email Contains Privileged and Confidential Information intended only for the personal and confidential use of the intended recipient(s). If the reader of this message is not the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to this message, calling the sender or calling our IT Security Officer at 1 (800) 975-4819, ext. 852.  You should also permanently delete original, reply, archive and all other copies of this message.     http://www.informeddna.com/

Ross Scroggs

unread,
Mar 21, 2024, 6:43:05 PM3/21/24
to google-ap...@googlegroups.com
Kris,

Send me a Meet/Zoom invitation and we'll investigate.

The 6.17.18 has been fixed in gam version checkrc

Ross
----
Ross Scroggs



--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/8bba6195-4982-408f-8846-5b9d33c009abn%40googlegroups.com.

Dan Casmas

unread,
Mar 28, 2024, 2:24:51 PM3/28/24
to GAM for Google Workspace
I wrote this to update

<#
.SYNOPSIS
    Upgrade GAMADV-XTD3 tool if a new version is available.

.DESCRIPTION
    This script checks if the GAM tool is installed and accessible in the system PATH. If it's installed,
    it checks the current version of GAMADV-XTD3 and compares it with the latest version available on GitHub.
    If an update is available, it downloads and upgrades GAMADV-XTD3.

.PARAMETER TempPath
    The path to the temporary directory where temporary files are stored. Default is 'C:\Temp'.

.PARAMETER DownloadPath
    The path where the downloaded files will be saved. Default is 'C:\Temp\gamdown'.

.EXAMPLE
    Upgrade-GAMADVXTD3 -TempPath "D:\Temp" -DownloadPath "D:\Temp\gamdown"
#>

param (
    [string]$TempPath = 'C:\Temp',
    [string]$DownloadPath = 'C:\Temp\gamdown'
)

try {
    # Check if GAM tool is installed and accessible in the system PATH.
    if (-not (Get-Command -Name gam.exe -ErrorAction SilentlyContinue)) {
        throw "GAM tool is not found. Please make sure it is installed and accessible in the system PATH."
    }

    # Check if TempPath is $null or empty. If yes, throw an error.
    if ([string]::IsNullOrWhiteSpace($TempPath)) {
        throw "TempPath parameter cannot be null or empty."
    }

    # Check if DownloadPath is $null or empty. If yes, throw an error.
    if ([string]::IsNullOrWhiteSpace($DownloadPath)) {
        throw "DownloadPath parameter cannot be null or empty."
    }

    # Check the current version of GAMADV-XTD3 and retrieve the latest version from GitHub.
    $GAMCheck = & gam.exe version checkrc

    $regex = '(?s)^.+\bCurrent: ([\d.]+).+\bLatest: ([\d.]+).*$'
    $CurrentVersion, $LatestVersion = -split (($GAMCheck -join "`n") -replace $regex, '$1 $2')

    # Check if GAM is properly installed and the version check returned an exit code of 1 (error).
    if ($LASTEXITCODE -eq 1) {    
        # Check if C:\Temp directory exists. If not, create it.
        if (-not (Test-Path $TempPath)) {
            New-Item -Path $TempPath -ItemType Directory -Force | Out-Null
        }  
   
        Write-Host "Upgrade needed ..."

        # Check if 'gamdown' directory exists. If yes, delete it.
        if (Test-Path $DownloadPath) {
            Remove-Item -Path $DownloadPath -Force -Recurse | Out-Null
        }

        # Create the 'gamdown' directory.
        New-Item -Path $DownloadPath -ItemType Directory -Force | Out-Null

        $DownloadURL = "https://github.com/taers232c/GAMADV-XTD3/releases/download/v$($LatestVersion)/gamadv-xtd3-$($LatestVersion)-windows-x86_64.zip"

        Invoke-WebRequest -Uri $DownloadURL -OutFile (Join-Path $DownloadPath 'output.zip') | Wait-Process

        Expand-Archive -Path (Join-Path $DownloadPath 'output.zip') -DestinationPath $DownloadPath -Force

        # Remove and move the upgraded directory to the installation directory.
        Remove-Item -LiteralPath 'C:\gamadv-xtd3\gam' -Force -Recurse
        Move-Item -Path (Join-Path $DownloadPath 'gamadv-xtd3') -Destination 'C:\gamadv-xtd3\gam' -Force
        Remove-Item -LiteralPath $DownloadPath -Force -Recurse

        $GAMCheck = & gam.exe version checkrc
        $NewCurrent = -split (($GAMCheck -join "`n") -replace $regex, '$1')

        return [PSCustomObject]@{    
            CurrentVersion = [string]$CurrentVersion
            LatestVersion  = [string]$LatestVersion
            Upgraded       = $true
            NewCurrent     = [string]$NewCurrent
            Result         = $LASTEXITCODE
        }
    }
    else {
        Write-Warning "No update needed."
        exit
    }
}
catch {
    Write-Warning $_
    exit
}

I am not responsible for problems
Reply all
Reply to author
Forward
0 new messages