GPO startup script keeps re-installing appls

88 views Asked by At

Hi I have the following issue. I have a PowerShell script to install software on domain users pcs using a GPO running on Active Directory Server. It installs the software successfully but when I restart the pc it runs the script again and re-installs the software. the script is below

#Script to install exe via GPO

$folder = 'C:\Program Files\Mind+' //the folder where it should be installed

if (-not (Test-Path -Path $Folder)) {
   
    start-process -FilePath "\\IT-SERVER.G-TESEK.com\APP-DEPLOYEMENT\mind+\Mind+_Win_V1.8.0_RC1.0.exe" -ArgumentList '/S'

    }

else  { }

Can someone help?. How do I have it only runs if the software is not already installed?

I have made the following edits using the sugestion from @NarayanaList and it works however when trying to log the result it fails. If I run it locally it works the result however when running it using GPO it does not any ideas?.

# Specify the name of the program you want to check
$programName = "Wireshark"

# Specify the path to the installer executable
$newInstallerPath = "\\IT-SERVER.G-TESEK.com\APP-DEPLOYEMENT\wireshark\Wireshark-win64-4.0.10.exe"

# Specify the path to the log file
$logFilePath = "\\IT-SERVER.G-TESEK.com\APP-DEPLOYEMENT\log_installed.txt"

# Function to check if a program is installed based on the registry path
function Is-ProgramInstalled {
    param (
        [string]$registryPath
    )

    # Attempt to find programs with names containing the specified programName
    $installedProgram = Get-ItemProperty -Path $registryPath -ErrorAction SilentlyContinue |
                       Where-Object { $_.DisplayName -like "*$programName*" }

    # Return true if the program is installed; otherwise, return false
    return [bool]($installedProgram -ne $null)
}

# Registry path for 64-bit programs
$x64RegistryPath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"

# Registry path for 32-bit programs on 64-bit systems
$x86RegistryPath = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"

# Get the computer host name
$computerName = $env:COMPUTERNAME

# Get the current date and time
$currentTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"

# Check if the program is installed
$programInstalled = Is-ProgramInstalled -registryPath $x64RegistryPath
if (-not $programInstalled) {
    $programInstalled = Is-ProgramInstalled -registryPath $x86RegistryPath
}

# If the program is not installed, install it
if (-not $programInstalled) {
    Write-Host "$programName is not installed. Installing now..."

    # Install the program
    Write-Host "Installing $programName..."
    Start-Process -FilePath $newInstallerPath -ArgumentList '/S' -Wait

    $logMessage = "$currentTime - $computerName $programName has been installed successfully."
} else {
    $logMessage = "$currentTime - $computerName $programName is already installed."
}

# Log the result to the file
Add-Content -Path $logFilePath -Value $logMessage
Write-Host "Log entry added to $logFilePath"
Write-Host $logMessage
0

There are 0 answers