function Install-AlkamiPackage { <# .SYNOPSIS Install-AlkamiPackage is a replacement for chocolatey that can do the relevant 90% of what Chocolatey does that Alkamists typically rely on on a regular basis. .DESCRIPTION This is not a 1:1 replacement for chocolatey nor should it be considered as such. If packages have an AlkamiManifest, then no included scripts will be run even when RunScripts is present. Instead the expected path for a given manifested package will be executed natively. The converse, however, will hold. If IgnoreScripts is specified, even the expected manifested package install will not occur. .PARAMETER PackageId This is a space, comma, or semicolon delimited list of packages to be installed. The specified version will apply to all packages in this list. See alternatively: -FormattedPackageList .PARAMETER PackageVersion This is the version that will be applied to all packages to be installed. When absent will default to the latest available package. .PARAMETER Latest Defaults to true. When the version is not specified in PackageVersion, will attempt to find the latest package version. When set to false, and no PackageVersion is provided, will error. .PARAMETER Feed This is where to find the package(s). When not specified, will check all the feeds listed in the naive chocolatey feed folder, as well as a global feed cache at each of the following locations: (cumulatively merged) * (Get-ProgramDataPath)\Alkami\Installer\feeds.config (xml) * (Get-ProgramDataPath)\Alkami\Installer\feeds.json * \.Alkami\Installer\feeds.config (xml) * \.Alkami\Installer\feeds.json The reason for multiple feed files is to allow for user and machine specification, as well as managed (xml) versus locally configured (json) global values. .PARAMETER RunScripts Run included scripts (when package does not contain an AlkamiManifest at the root, this will execute Alkami code paths for manifested packages) Note: No "chocolatey provided" functions exist. This is intentional. To set this value globally, use the next line, substituting Machine for User as appropriately desired Set-EnvironmentVariable -Key 'ALKAMI__InstallPackages__AlwaysRunScripts' -Value 'true' -StoreName User .PARAMETER IgnoreScripts Do not run any included scripts. Will not execute Alkami code paths. To set this value globally, use the next line, substituting Machine for User as appropriately desired Set-EnvironmentVariable -Key 'ALKAMI__InstallPackages__AlwaysRunScripts' -Value 'false' -StoreName User .PARAMETER IgnoreDependencies Will not try to resolve package dependencies. Defaults to false (will attempt to download and install dependency packages - obeys the RunScripts/IngoreScripts flag) This flag is overridden by ForceDependencies. To set this value globally, use the next line, substituting Machine for User as appropriately desired Set-EnvironmentVariable -Key 'ALKAMI__InstallPackages__IgnoreDependencies' -Value 'true' -StoreName User .PARAMETER ForceDependencies Will try to resolve package dependencies. Will honor the RunScripts/IgnoreScripts flag as appropriate. This flag overrides IgnoreDependencies. To set this value globally, use the next line, substituting Machine for User as appropriately desired Set-EnvironmentVariable -Key 'ALKAMI__InstallPackages__ForceDependencies' -Value 'true' -StoreName User .PARAMETER NoProgress This switch will hide output on progression in scenarios where a visual guide would be presented. .PARAMETER StopOnFirstFailure Will attempt to stop on first failure execution. Not all task segments support stopping on first failure. .PARAMETER LimitOutput Will reduce the number of output lines where possible. Some output may be unpreventable. .PARAMETER Timeout Per package process timeout. Not adhered to for all action steps. .PARAMETER Force When preesented with a yes/no scenario, will always choose yes, even if destructive. This switch is overridden by WhatIf. .PARAMETER WhatIf When preseneted with a yes/no scenario, will always choose no. Attempts to not alter system state. This switch overrides Force. #> [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 0, ValueFromRemainingArguments = $true)] [Alias('Name')] [Alias('Id')] [string[]]$PackageId, [Alias('Version')] [Alias('v')] [string]$PackageVersion, [string[]]$FormattedPackageList, [switch]$Latest = $true, [Parameter()] [Alias('Source')] [Alias('s')] [Alias('FeedUrl')] [string]$Feed, [Alias('y')] [Alias('confirm')] [Alias('yes')] [switch]$RunScripts, [Alias('n')] [Alias('no')] [Alias('SkipScripts')] [switch]$IgnoreScripts, [Parameter()] [switch]$NoProgress, [Parameter()] [Alias('pre')] [Alias('usePre')] [Alias('prerelease')] [switch]$AllowPrereleasePackages, [Parameter()] [Alias('i')] [switch]$IgnoreDependencies, [Parameter()] [Alias('x')] [switch]$ForceDependencies, [switch]$StopOnFirstFailure, [Parameter()] [Alias('r')] [switch]$LimitOutput, [Parameter()] [int]$Timeout = 2700, [Parameter()] [switch]$Force, [Parameter()] [switch]$WhatIf ) $logLead = Get-LogLeadName Write-Host $PackageId if ($WhatIf) { Write-Host "!! WHATIF MODE ENABLED !!`n" if ($Force) { Write-Host "$logLead : WhatIf mode enabled, disabling -Force flag" } } if (-not $Latest -and [string]::IsNullOrWhiteSpace($PackageVersion)) { throw "$logLead : Must specify a PackageVersion when specifying Latest:`$false" } if (-not $RunScripts -and -not $IgnoreScripts) { $runscriptEnvVarName = "ALKAMI__InstallPackages__AlwaysRunScripts" $existingVar = Get-EnvironmentVariable -Key $runscriptEnvVarName $RunScripts = $existingVar -eq 'true' $IgnoreScripts = $existingVar -ne 'true' if (!$LimitOutput) { if ([string]::IsNullOrWhiteSpace($existingVar)) { Write-Host "$logLead : Neither RunScripts nor IgnoreScripts were specified. Will default to IgnoreScripts. If you want to enable running scripts by default for the future, please run the following command`n`n`tSet-EnvironmentVariable -Key $runscriptEnvVarName -Value 'true' -StoreName User`n`nYou can set the store to Machine as well if you want it to apply to all users, or set the global value to false, etc" } } } if ($AllowPrereleasePackages -and -not [string]::IsNullOrWhiteSpace($PackageVersion)) { Write-Warning "$logLead : Can not specify version and ask for allowing prerelease versions to be installed. Please adjust input in the future." } }