########################## # Writer: Claudio Boggian # Company: PAL s.r.l. #------------------------- # Date: 2023/02/28 # v: 1.0 # Reason: Emission #------------------------- ########################## # This is needed to run the software in debug mode Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass # Importing base functions . \\pal.local\NETLOGON\Powershell\Base-Functions.ps1 $latestDate = "28/02/2023" # First release $scriptUser = "CBO" $latestVersion = "1.0.0" $displayName = "IcingaAgent - Software Installation Script" #region Initialization $logString = "`r`n" $logString += "#################################`r`n" $logString += "# __________ _____ .____ #`r`n" $logString += "# \______ \/ _ \ | | #`r`n" $logString += "# | ___/ /_\ \| | #`r`n" $logString += "# | | / | \ |___ #`r`n" $logString += "# |____| \____|__ /_______ \ #`r`n" $logString += "# \/ \/ #`r`n" $logString += "# #`r`n" $logString += "#################################`r`n" $logString += "`r`n" $logString += "`r`n" $logString += " *** $displayName *** `r`n" $logString += "`r`n" $logString += " Date: $($latestDate)`r`n" $logString += " User: $($scriptUser)`r`n" $logString += " Version: $($latestVersion)`r`n" $logString += "`r`n" #endregion $policyGroup = "PAL SFTW ICINGA" $serviceName = 'Icinga 2' try { #Check device policy # if(!(Get-IsComputerMemberOf -Group $policyGroup)) { # $logString += "$env:COMPUTERNAME non appartiene al gruppo $policyGroup`r`n" # throw $logString # } $logString += "Initializing IcingaAgent...`r`n" $logString += Initialize-Icinga $logString += "Done!`r`n" $logString += "Initializing installation IcingaAgent...`r`n" #Icinga install/update if(Install-IcingaAgent -Version 'release' -AllowUpdates 1){ $logString += "`r`nInstall success!`r`n" } else { $logString += "`r`n Icinga Agent is already at last version`r`n" } $service = Get-Service -Name $serviceName $logString += "Check status service $serviceName`r`n" #Check Service if(!($service.Status -eq 'Running')){ $logString += "`r`nService not found, start uninstall`r`n" if($logString += Uninstall-IcingaAgent){ $logString += "`r`nRestart installation`r`n" $logString += Install-IcingaAgent -Version 'release' -AllowUpdates 1 if(!($service.Status -eq 'Running')){ $logString += "`r`nService up and running`r`n" } } else { $logString += "`r`nUninstall failed`r`n" } } else { $logString += "`r`nService up and running`r`n" } } catch { $logString += "$_`r`n" } Write-Log $displayName $logString #TODO Da importare in Base-Functions.ps1 function Initialize-Icinga { $logString = ""; $icingaModule = "icinga-powershell-framework"; try{ if(!(Get-InstalledicingaModule -Name $icingaModule)){ $logString += "Installing icinga module...`r`n" $logString += Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force $logString += Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted $logString += Install-Module -Name $icingaModule $logString += "Icinga module installed!`r`n" } if(!(Get-Module -Name $icingaModule)){ $logString += "Importing icinga module...`r`n" $logString += Import-Module -Name $icingaModule $logString += "Icinga module imported!`r`n" } }catch{ $logString += "$_`r`n" } return $logString }