Skip to content

Instantly share code, notes, and snippets.

@LudovicOmarini
Last active August 12, 2021 11:17
Show Gist options
  • Save LudovicOmarini/6fe15e95b298fbeac5066bf23eb20231 to your computer and use it in GitHub Desktop.
Save LudovicOmarini/6fe15e95b298fbeac5066bf23eb20231 to your computer and use it in GitHub Desktop.
This script install FusionInventory Agent by GPO if there is not installed or if the executable is in a newer version.
::.SYNOPSIS:
:: Deploy FusionInventory Agent by GPO.
::
::.DESCRIPTION:
:: This script install FusionInventory Agent by GPO if there is not installed or if the executable is in a newer version.
:: He also detect if it's a x86 or x64 computer to install the good executable.
:: First, you have to download the latest executables of FusionInventory Agent (x86 and x64) and link them to this script.
:: Don't forget to set your LimitDate, change your GLPI server adresse and change TAG.
:: LimitDate is the date that the script stop running.
:: You can create multiple GPOs with multiple scripts and differents TAG to organize them on FusionInventory.
::
::.EXEMPLE:
:: .\Deploy_FusionInventoryAgent.bat
if exist %ProgramFiles%\FusionInventory-Agent\Uninstall.exe (
FOR %%? IN ("%ProgramFiles%\FusionInventory-Agent\Uninstall.exe") DO (set installdate=%%~t?)
set /a InstallationDate=%installdate:~6,4%%installdate:~3,2%%installdate:~0,2%
:: Here you can set the limit date at format YYYYMMDD
set /a LimitDate=YYYYMMDD
if %LimitDate% GEQ %InstallationDate% (
Taskkill /IM perl.exe /F
Taskkill /IM fusioninventory-agent.exe /F
"%ProgramFiles%\FusionInventory-Agent\Uninstall.exe" /S
rmdir "%ProgramFiles%\FusionInventory-Agent" /S /Q
)
)
cd "%ProgramFiles%"
for /f "tokens=*" %%a in ('powershell "(gi \\Path\fusioninventory-agent-windows-x64.exe).versioninfo.Fileversion"') DO SET NEWVERSION=%%a
for /f "tokens=*" %%a in ('powershell "(gi .\FusionInventory-Agent\Uninstall.exe).versioninfo.Fileversion"') DO SET VERSION=%%a
IF %PROCESSOR_ARCHITECTURE%==x86 (goto x86)
IF %PROCESSOR_ARCHITECTURE%==AMD64 (goto x64)
:x64
IF NOT EXIST "%ProgramFiles%\FusionInventory-Agent\var" (
:: Path to x64 executable and don't forget to set server and tag parameters
\\Path\fusioninventory-agent-windows-x64.exe /S /acceptlicense /installtasks=full /add-firewall-exception /execmode=Service /server="http://server/glpi/plugins/fusioninventory/" /runnow /tag="YourTag"
goto end
)
IF EXIST "%ProgramFiles%\FusionInventory-Agent\var" (
IF %NEWVERSION% gtr %VERSION% (
:: Path to x64 executable and don't forget to set server and tag parameters
\\Path\fusioninventory-agent-windows-x64.exe /S /acceptlicense /installtasks=full /add-firewall-exception /execmode=Service /server="http://server/glpi/plugins/fusioninventory/" /runnow /tag="YourTag"
)
goto end
)
:x86
IF NOT EXIST "%ProgramFiles%\FusionInventory-Agent\var" (
:: Path to x86 executable and don't forget to set server and tag parameters
\\Path\fusioninventory-agent-windows-x86.exe /S /acceptlicense /installtasks=full /add-firewall-exception /execmode=Service /server="http://server/glpi/plugins/fusioninventory/" /runnow /tag="YourTag"
goto end
)
IF EXIST "%ProgramFiles%\FusionInventory-Agent\var" (
IF %NEWVERSION% gtr %VERSION% (
:: Path to x86 executable and don't forget to set server and tag parameters
\\Path\fusioninventory-agent-windows-x86.exe /S /acceptlicense /installtasks=full /add-firewall-exception /execmode=Service /server="http://server/glpi/plugins/fusioninventory/" /runnow /tag="YourTag"
)
goto end
)
:end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment