Uninstalling Git and Reinstalling newer verion of GIt on Intune Devices

Daniel Bulakh 25 Reputation points
2024-06-10T13:51:46.8766667+00:00

Hello,

Me and my team are struggling to push a script via Intune to uninstall the previous verion of Git while installing the newest version of Git on company devices via a script in Intune

The previous verion of Git has vulnerabilities and so we would like to silently uninstall it and reinstall the newest version

We add the script and deploy it as an app in Win32, but installation works for users that don't have git, but if they have git Intune just marked as installed but doesn't install the latest version

This is the script-

Define the URL for the latest Git installer

$GitInstallerUrl = "https://github.com/git-for-windows/git/releases/download/v2.45.2.windows.1/Git-2.45.2-64-bit.exe"

$InstallerPath = "$env:TEMP\Git-2.45.2-64-bit.exe"

Download the Git installer

Write-Output "Downloading the latest Git installer..."

Invoke-WebRequest -Uri $GitInstallerUrl -OutFile $InstallerPath

Check if the installer was downloaded successfully

if (Test-Path $InstallerPath) {

Write-Output "Git installer downloaded successfully."

Install Git silently

Write-Output "Installing Git..."

Start-Process -FilePath $InstallerPath -ArgumentList "/SILENT" -NoNewWindow -Wait -PassThru

Check if Git was installed successfully

if (Test-Path "C:\Program Files\Git\bin\git.exe") {

Write-Output "Git installed successfully."

} else {

Write-Output "Git installation failed."

}

Remove the installer file after installation

Remove-Item -Path $InstallerPath -Force

Write-Output "Cleaned up installer file."

} else {

Write-Output "Failed to download the Git installer."

}

Microsoft Security Intune Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Crystal-MSFT 53,981 Reputation points Microsoft External Staff
    2024-06-11T01:18:22.29+00:00

    @Daniel Bulakh, Thanks for posting in Q&A. From your description, the win32 app shows installed without installing the new version on the device which is with previous version. Based on my experience, the issue can be with the detection rule. In fact, detection rule is used to detect if the app is installed on the device. If the detection rule we configure also satisfy the previous version, then it will consider the app is already installed and not do next.

    https://learn.microsoft.com/en-us/mem/intune/apps/apps-win32-add#step-4-detection-rules

    Please check on the detection rule and make sure the registry or file we configure is only for the new version. If there's any update, feel free to let us know.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.