ps script for updating gam7?

51 views
Skip to first unread message

James Hatz

unread,
Oct 30, 2025, 11:23:52 AM (8 days ago) Oct 30
to google-ap...@googlegroups.com
I had a script someone shared that updated advanced gam - and lol @ me I ran it this morning thinking it might still work.. it does.. if you want advanced gam 7.05 instead of Gam7 :) 

Don't fret - I downloaded the MSI to correct my blunder - but was wondering if there was a new script out there that would shave a few seconds off my day from going to Github to check for new releases ? 

If not .. I'll survive .. this is a first world type "problem" after all.  :) 


James Hatz
Technology Coordinator
Rush City Schools 139
Rush City MN 55069

Help prevent SPAM & SCAMS:  Think before you click!
"You may delay, but time will not, and lost time is never found again." - Benjamin Franklin 

Ross Scroggs

unread,
Oct 30, 2025, 11:25:58 AM (8 days ago) Oct 30
to google-ap...@googlegroups.com
Show the script, we should be able to edit it for GAM7.

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 visit https://groups.google.com/d/msgid/google-apps-manager/CAOGTeFEntM2nnvLFjSpAAKK43cY2svrVGpxT4s24GVONnisQzA%40mail.gmail.com.

James Hatz

unread,
Oct 30, 2025, 2:57:55 PM (8 days ago) Oct 30
to GAM for Google Workspace
#--------no modules
Try {
    If (!(Test-Path C:\Temp)) {
        New-Item -Path C:\Temp -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
    }
}
Catch {
    Write-Warning "This is a windows only script or C:\Temp Directory can't be used / created"
    Break Script
}

$current = $null
$latest = $null
$newCurrent = $null
$resultsarray = @()
$GamCheck = $null
Try {
    Test-Path C:\GAMADV-XTD3\

    $GamCheck = invoke-command -ScriptBlock { C:\GAMADV-XTD3\gam.exe version checkrc }
}
Catch {
    Write-Warning "Go to https://github.com/taers232c/GAMADV-XTD3/releases and download the current GAM and then install GAM in C:\GAMADV-XTD3\"
   
    $filename = 'C:\Temp\Gaminstall.csv'
   
    $resultsarray = [PSCustomObject]@{    
        'Install_GAMADV-XTD3'     = "https://github.com/taers232c/GAMADV-XTD3/releases"
        DirectoryForXTD3NeedsToBe = 'C:\GAMADV-XTD3\'
    }
 
    $resultsarray | Export-Csv $filename -NoTypeInformation | Format-Table text-align=left -AutoSize
    $GamCheck = $null
}
   
If ($GamCheck) {
    $current = $GamCheck.split(":")[19].Trim()
    $latest = $GamCheck.split(":")[21].Trim()
   
    If ($LASTEXITCODE -eq 1) {  
        Try {
            $client = new-object System.Net.WebClient
            $client.DownloadFile("https://github.com/taers232c/GAMADV-XTD3/releases/download/v$latest/gamadv-xtd3-$latest-windows-x86_64.msi", "C:\Temp\gamadv-xtd3-$latest-windows-x86_64.msi")
            Start-Process -Filepath "C:\Temp\gamadv-xtd3-$latest-windows-x86_64.msi" -ArgumentList "/passive" -Wait | Wait-Process -Timeout 60
            Remove-Item "C:\Temp\gamadv-xtd3-$latest-windows-x86_64.msi"
 
            $filename = 'C:\Temp\Gamupgraded.csv'

            $NeedUpGradeCode = $LASTEXITCODE
 
            $GamCheck = $null
            $GamCheck = invoke-command -ScriptBlock { C:\GAMADV-XTD3\gam.exe version checkrc }
            $newCurrent = $GamCheck.split(":")[19].Trim()
   
            $resultsarray = [PSCustomObject]@{    
                CurrentVersion   = $current
                LatestVersion    = $latest
                NeedUpgradeCode  = $NeedUpGradeCode
                Upgraded         = $true
                NewCurrent       = $newCurrent
                AfterUpgradeCode = $LASTEXITCODE
            }
            write-host "Version upgraded $latest" -ForegroundColor Blue
            write-host "$resultsarray" -ForegroundColor Blue
            $resultsarray | Export-Csv $filename -NoTypeInformation | Format-Table text-align=left -AutoSize
        }
        Catch {
            Write-Warning "Problem with site or command. Maybe go to https://github.com/taers232c/GAMADV-XTD3/releases and download the current GAM and then install GAM in C:\GAMADV-XTD3\ again"
            $filename = 'C:\Temp\Gaminstall.csv'
   
            $resultsarray = [PSCustomObject]@{    
                'Install_GAMADV-XTD3'     = "https://github.com/taers232c/GAMADV-XTD3/releases"
                DirectoryForXTD3NeedsToBe = 'C:\GAMADV-XTD3\'
                unknownError              = $true
                Error                     = $LASTEXITCODE
                Upgraded                  = $False
            }
         
            $resultsarray | Export-Csv $filename -NoTypeInformation | Format-Table text-align=left -AutoSize
        }
    }
    Else {
        $filename = 'C:\Temp\GamCurrent.csv'
        $resultsarray = [PSCustomObject]@{    
            CurrentVersion = $current
            LatestVersion  = $latest
            Error          = $LASTEXITCODE
            Upgraded       = $false
        }
        write-host "Gam version is current $current" -ForegroundColor Green
        write-host "$resultsarray" -ForegroundColor Green

        $resultsarray | Export-Csv $filename -NoTypeInformation | Format-Table text-align=left -AutoSize
    }
}

Return $filename

James Hatz

unread,
Oct 30, 2025, 3:00:22 PM (8 days ago) Oct 30
to GAM for Google Workspace
This is a newer version I believe - less "wordy" than the one I just posted:

if (.\gam version checkrc) {
  $releases = curl "https://api.github.com/repos/taers232c/GAMADV-XTD3/releases" | ConvertFrom-Json
  $dlurl = ($releases[0].assets | where {$_.name -like "*windows*64.zip"}).browser_download_url
  $dir = (Get-Location).Path
  (new-object System.Net.WebClient).DownloadFile($dlurl, "$dir\gamadv-xtd3-latest-windows-x86_64.zip")
  $oldchangeloglinescount=(Get-Content .\GamUpdate.txt | Select-String .*).count
  Expand-Archive "$dir\gamadv-xtd3-latest-windows-x86_64.zip" "$dir\" -Force
  mv "$dir\gamadv-xtd3\*" "$dir\" -Force
  rm "$dir\gamadv-xtd3\"
  $newchangeloglinescount=(Get-Content .\GamUpdate.txt | Select-String .*).count
  Get-Content .\GamUpdate.txt -Head ($newchangeloglinescount-$oldchangeloglinescount-1)
} else {
  # Nothing, GAM is already up-to-date

On Thursday, October 30, 2025 at 10:25:58 AM UTC-5 Ross Scroggs wrote:

Ross Scroggs

unread,
Oct 30, 2025, 3:04:29 PM (8 days ago) Oct 30
to google-ap...@googlegroups.com
Send me a Meet/Zoom invitation and we'll update it.

Ross
----
Ross Scroggs


Ross Scroggs

unread,
Oct 30, 2025, 3:07:58 PM (8 days ago) Oct 30
to google-ap...@googlegroups.com
Change taers232c/GAMADV-XTD3 ro GAM-team/GAM
----
Ross Scroggs



James Hatz

unread,
Oct 30, 2025, 3:43:51 PM (8 days ago) Oct 30
to google-ap...@googlegroups.com
You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/o1Wwedy4izI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-man...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-manager/2828E829-CAFB-43B9-816A-245BD06CDF38%40gmail.com.

Ross Scroggs

unread,
Oct 30, 2025, 4:33:05 PM (8 days ago) Oct 30
to google-ap...@googlegroups.com

Chris River

unread,
Oct 31, 2025, 11:10:29 AM (7 days ago) Oct 31
to GAM for Google Workspace
I just added a pull request for that version of the script, to automatically determine the gam installation location and Windows architecture version, to make the script a little easier to use. I don't have an ARM system to validate the ARM piece, but otherwise my testing of the script seems to work as expected:

# Just like the script for GAMADV-XTD3, this is not my script originally.
# It was created by Chris River (on request by Gabriel Clifton) and amended by Paul Ogier.
# That process can be seen here.
# https://groups.google.com/g/google-apps-manager/c/k2JEsdT6jcs/m/DdrLY_GcBQAJ

# I updated the script to make it possible to run the script regardless of where the user is, and also to run it automatically.
# This script must be run as an administrator

# Check the version of GAM7 and update if new version exists
## There's now an ARM version for Windows, so code needed one more variable.

# Set this to $false if you do not want to see the change log output
$ShowChangeLog = $true

# If GAM's installation location cannot be automatically located, then this variable MUST be adjusted to match your system.
# Where is GAM7 installed?
$dir = ""

# Try to automatically find the install location for GAM
$gam = Get-Command gam -ErrorAction SilentlyContinue
if (-not $gam -or -not $gam.Source) {
  if ($dir -and -not (Test-Path $dir -PathType Container)) {
    throw "$dir not found or is not a valid folder path. Edit this script located at $PSCommandPath to manually set the `$dir variable value to an existing folder path"
  } elseif (-not $dir) {
    throw "Unable to automatically locate GAM installation location. Manually (re)install GAM, or edit this script located at $PSCommandPath to manually set the `$dir variable value"
  }
} else {
  $dir = Split-Path $gam.Source -Parent
}

# Automatically determine which Windows architecture version to download
$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
$winversion = switch ($architecture) {
    "X64"  { "windows-x86_64.zip" }
    "X86"  { "windows-x86_64.zip" }
    "Arm"  { "windows-arm64.zip" }
    "Arm64" { "windows-arm64.zip" }
    Default { throw "Unknown Windows architecture. You may need to manually specify the `$winversion variable in $PSCommandPath" }
}

# HERE BE DRAGONS!
# Do not change anything below.
# Create a new variable pointing directly to the gam binary.
$gam = "$dir\gam.exe"

# Check if there is a new version.
$version = &$gam --% version checkrc

# If the last exit code is 1, GAM7 is not up-to-date.
if ($lastexitcode -eq 1) {
  # Display a message saying that there is an update available and that it will be updated. Disable if script is to run automatically.
  Write-Host "GAM7 will be updated" -ForegroundColor Red -BackgroundColor White
 
  # Get the latest release from the GAM7 repository on GitHub.
  $releases = curl "https://api.github.com/repos/GAM-team/GAM/releases" | ConvertFrom-Json
  # Get the download URL for the latest release.
  $dlurl = ($releases[0].assets | where {$_.name -like "*$winversion"}).browser_download_url
  # Download the latest release.
  (New-Object System.Net.WebClient).DownloadFile($dlurl, "$dir\gam7-latest-$winversion")
 
    # Save the number of lines in the current change log. Disable if script is to run automatically.
  $oldchangeloglinescount=(Get-Content $dir\GamUpdate.txt | Select-String .*).count
 
  # Extract the contents of the zip file to a temporary directory.
  # The \gam7 path is included in the zip and may have to be adjusted if it's changed in the future.
  Expand-Archive "$dir\gam7-latest-$winversion" "$dir\" -Force
  # Copy the extracted files to the current location.
  Copy-Item "$dir\gam7\*" "$dir\" -Force -Recurse
  # Remove the temporary directory.
  rm "$dir\gam7" -Force -Recurse
 
  if ($ShowChangeLog -eq $true) {
    # Save the number of lines in the updated change log.
    $newchangeloglinescount=(Get-Content $dir\GamUpdate.txt | Select-String .*).count
    # Get and display the new lines in the change log.
    Write-Host "Latest Changes in GAM7" -ForegroundColor Red -BackgroundColor White
    Get-Content $dir\GamUpdate.txt -Head ($newchangeloglinescount-$oldchangeloglinescount)
  }

  # Display a message saying that GAM7 has been updated, then pause. Disable if script is to run automatically.
  Write-Host "GAM7 has been updated" -ForegroundColor Red -BackgroundColor White
} else {
  # Display a message saying GAM7 is already up-to-date, then pause. Disable if script is to run automatically.
  Write-Host "GAM7 is already up-to-date" -ForegroundColor Green

}
# If the script is to be run automatically, disable the Pause.
# You may also consider whether to disable all Write-Host lines, as you don't need that, since nobody is going to see them.
# Nor do you need the lines getting and showing the GamUpdate.txt file.
Pause


Reply all
Reply to author
Forward
0 new messages