This is a fork of PowerShell App Deployment Toolkit and it was modified so it can be installed as a PowerShell module.
In order for the PowerShell App Deployment Toolkit PowerShell module to load automatically when PowerShell is launched, you can copy the following code to the system PowerShell profile file located in C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1.
# Standalone application install script - (C)2023 Jonathan Pitre
#Requires -Version 5.1
#Requires -RunAsAdministrator
#---------------------------------------------------------[Initialisations]--------------------------------------------------------
$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "SilentlyContinue"
# Set the script execution policy for this process
Try { Set-ExecutionPolicy -ExecutionPolicy 'ByPass' -Scope 'Process' -Force } Catch {}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
Function Initialize-Module
{
<#
.SYNOPSIS
Initialize-Module install and import modules from PowerShell Galllery.
.OUTPUTS
System.String
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$Module
)
Write-Host -Object "Importing $Module module..." -ForegroundColor Green
# If module is imported say that and do nothing
If (Get-Module | Where-Object { $_.Name -eq $Module })
{
Write-Host -Object "Module $Module is already imported." -ForegroundColor Green
}
Else
{
# If module is not imported, but available on disk then import
If ( [bool](Get-Module -ListAvailable | Where-Object { $_.Name -eq $Module }) )
{
$InstalledModuleVersion = (Get-InstalledModule -Name $Module).Version
$ModuleVersion = (Find-Module -Name $Module).Version
$ModulePath = (Get-InstalledModule -Name $Module).InstalledLocation
$ModulePath = (Get-Item -Path $ModulePath).Parent.FullName
If ([version]$ModuleVersion -gt [version]$InstalledModuleVersion)
{
Update-Module -Name $Module -Force
Remove-Item -Path $ModulePath\$InstalledModuleVersion -Force -Recurse
Write-Host -Object "Module $Module was updated." -ForegroundColor Green
}
Import-Module -Name $Module -Force -Global -DisableNameChecking
Write-Host -Object "Module $Module was imported." -ForegroundColor Green
}
Else
{
# Install Nuget
If (-not(Get-PackageProvider -ListAvailable -Name NuGet))
{
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Write-Host -Object "Package provider NuGet was installed." -ForegroundColor Green
}
# Add the Powershell Gallery as trusted repository
If ((Get-PSRepository -Name "PSGallery").InstallationPolicy -eq "Untrusted")
{
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Write-Host -Object "PowerShell Gallery is now a trusted repository." -ForegroundColor Green
}
# Update PowerShellGet
$InstalledPSGetVersion = (Get-PackageProvider -Name PowerShellGet).Version
$PSGetVersion = [version](Find-PackageProvider -Name PowerShellGet).Version
If ($PSGetVersion -gt $InstalledPSGetVersion)
{
Install-PackageProvider -Name PowerShellGet -Force
Write-Host -Object "PowerShellGet Gallery was updated." -ForegroundColor Green
}
# If module is not imported, not available on disk, but is in online gallery then install and import
If (Find-Module -Name $Module | Where-Object { $_.Name -eq $Module })
{
# Install and import module
Install-Module -Name $Module -AllowClobber -Force -Scope AllUsers
Import-Module -Name $Module -Force -Global -DisableNameChecking
Write-Host -Object "Module $Module was installed and imported." -ForegroundColor Green
}
Else
{
# If the module is not imported, not available and not in the online gallery then abort
Write-Host -Object "Module $Module was not imported, not available and not in an online gallery, exiting." -ForegroundColor Red
Exit 1
}
}
}
}
# Install and import module
Initialize-Module -Module "PSADT"
You can use the cmdlet Show-HelpConsole or the alias Get-PSADTHelp to launch the PowerShell App Deployment Toolkit help console.
All variables from AppDeployToolMain.ps1 are available for use once a cmdlet is executed. It should cover most of your needs to detect the system environment you're running your installation script from. Run Get-Variable to see the full list.
My intend for this module was to combine the power of PowerShell App Deployment Toolkit and the Evergreen module to create the perfect installation scripts for all your Windows applications. I will provide some examples in the future in this GitHub repo.