Create Active Setup

From psadt | Evergreen Application Management
Jump to navigation Jump to search

About

Powershell.png

PowerShell function to create an Active Setup for applying user configuration at logon by calling a separate script named ActiveSetup.ps1.

Note:

  • $appName is the name of your given application
  • $appGUID is the unique GUID for your application (this can be whatever you like)
  • The version number is arbitrary and so I have elected to use the current date at creation


Function

#region Function Create-ActiveSetup
Function Create-ActiveSetup {
<#
.SYNOPSIS
	Creates Active Setup.
.DESCRIPTION
.PARAMETER
.LINK
	http://psadt.com/
#>

Begin	{
	$ActiveSetupPath = "$env:ProgramData\ActiveSetup\$appName"
	$ActiveSetupConfig = "HKLM:\SOFTWARE\Microsoft\Active Setup\Installed Components\$appGUID"
	$ActiveSetupDate = (Get-Date -UFormat %Y`,`%m`,`%d)
	If (!(Test-Path $ActiveSetupPath))
		{New-Item -ItemType Directory $ActiveSetupPath -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue}
	If (Test-Path $ActiveSetupPath)
		{Copy-File -Path "$dirSupportFiles\*" -Destination $ActiveSetupPath\ -Recurse}
	If (!(Test-Path $ActiveSetupConfig))
		{New-Item -ItemType Directory $ActiveSetupConfig -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue}
	If (Test-Path $ActiveSetupConfig)
		{
		New-ItemProperty -Path $ActiveSetupConfig -Name "StubPath" -Value "`"$PSHOME\powershell.exe`" -WindowStyle Hidden -ExecutionPolicy RemoteSigned -File `"$ActiveSetupPath\ActiveSetup.ps1`"" -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
        New-ItemProperty -Path $ActiveSetupConfig -Name "Version" -Value $ActiveSetupDate -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
        New-ItemProperty -Path $ActiveSetupConfig -Name "(Default)" -Value $appCustomName -force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
		}
	}
}

#endregion

For removal, see Remove Active Setup.