Created
August 21, 2023 17:40
-
-
Save dancing-groot/d2df304c8dad7c99d538525d7aa9d4b3 to your computer and use it in GitHub Desktop.
Install an application with Evergreen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region FUNCTIONS | |
function Install-AppWithEvergreen | |
{ | |
param | |
( | |
[string]$EvergreenAppName, | |
[scriptblock]$EvergreenArgs, | |
[string]$AppInstallerArgs | |
) | |
# Download Latest version of application via Evergreen | |
$App = Get-EvergreenApp -Name $EvergreenAppName | Where-Object { $EvergreenArgs.Invoke() } | Select-Object -First 1 | |
$AppInstallerFile = $App | Save-EvergreenApp -Path "C:\ProgramData\Evergreen\$EvergreenName" | |
# Install application | |
Start-Process "$AppInstallerFile" -ArgumentList $AppInstallerArgs -NoNewWindow -Wait -Verbose | |
# Cleanup temp directory | |
$AppInstaller | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue | |
} # Install-AppWithEvergreen | |
#endregion FUNCTIONS | |
#region PREREQUISITES | |
# Trust PowerShell Gallery | |
if (Get-PSRepository | Where-Object { $_.Name -eq "PSGallery" -and $_.InstallationPolicy -ne "Trusted" }) | |
{ | |
Install-PackageProvider -Name "NuGet" -MinimumVersion 2.8.5.208 -Force | |
Set-PSRepository -Name "PSGallery" -InstallationPolicy "Trusted" | |
} | |
# Install or update Evergreen module | |
$Installed = Get-Module -Name "Evergreen" -ListAvailable | ` | |
Sort-Object -Property @{ Expression = { [System.Version]$_.Version }; Descending = $true } | ` | |
Select-Object -First 1 | |
$Published = Find-Module -Name "Evergreen" | |
if ($Null -eq $Installed) | |
{ | |
Install-Module -Name "Evergreen" | |
} | |
elseif ([System.Version]$Published.Version -gt [System.Version]$Installed.Version) | |
{ | |
Update-Module -Name "Evergreen" | |
} | |
#endregion PREREQUISITES | |
#region MAIN | |
# Notepad++ | |
$AppName = "NotepadPlusPlus" | |
$SearchArguments = { $_.Architecture -eq "x64" -and $_.Type -eq "exe" } | |
$InstallerArgs = '/S' | |
Install-AppWithEvergreen -EvergreenAppName $AppName -EvergreenArgs $SearchArguments -AppInstallerArgs $InstallerArgs | |
#endregion MAIN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment