Skip to content

PowerPacks

Not sure which scripting surface to use? See Automation and scripting for how PowerPacks, the VB Scripting Library, and the SDK compare.

When you create a PowerPack in the CapaInstaller Console, it gets an install script and an uninstall script built from a template. Both scripts have the same sections:

Section What it contains Edit it?
Param block The parameters that CapaInstaller passes to the script: $Packageroot, $AppName, $AppRelease, $LogFile, $TempFolder, $DllPath and $InputObject. No
#### VARIABLES #### $global:DownloadPackage and $global:MinimumDiskspaceMB, followed by a # DO NOT CHANGE THESE VARIABLES block that copies the parameters into global variables. Only the two settings
#### FUNCTIONS #### PreInstall, Install and PostInstall in the install script, or PreUninstall, Uninstall and PostUninstall in the uninstall script. PreInstall and PreUninstall start with a free disk space check against $global:MinimumDiskspaceMB. Yes — your code goes here
#### MAIN #### Loads PSlib.psm1, runs Add-PSDll, $cs.Job_Start and Initialize-Variables, and then calls your functions. No

The two templates differ only in their function names and their defaults:

Setting Install template Uninstall template
$global:DownloadPackage $true $false
$global:MinimumDiskspaceMB 1500 0

#### MAIN #### runs the script in this order:

  1. PreInstall (or PreUninstall).
  2. Start-PSDownloadPackage, if $global:DownloadPackage is $true and the script runs through the CapaInstaller agent.
  3. Install (or Uninstall).
  4. PostInstall (or PostUninstall).
  5. Exit-PSScript 0. If any step throws an exception that your code doesn’t catch, the script ends instead with Exit-PSScript and the exception’s HResult as the exit code.

Everything you can use in a PowerPack script is listed below. Click a function for its parameters and examples.

Page What it covers
PowerPack Global Variables The $global: variables set by the script template and Initialize-Variables: paths, OS and hardware info, and job settings.
PowerShell CMS Functions The CMS_* functions that talk to the management server: inventory, group membership, package status, and agent control.
PowerPack tips and examples Worked examples for common PowerPack tasks.
Function What it does
Add-PSDll Loads the CapaOne.ScriptingLibrary .NET assembly from $DllPath and creates the $cs object that every $cs.* helper call in a PowerPack script goes through.
Initialize-Variables Populates the $global:gs* variables (program paths, Windows directories, OS version and edition, computer hardware info, job configuration) and $global:AppLogFolder at the start of a PowerPack script.
Start-PSDownloadPackage Triggers the download of the package’s kit folder from CiBaseAgent, then polls the download progress once per second, logging it, until it reaches 100%.
Exit-PSScript Ends a PowerPack script with a specific exit code, logging the outcome before the script terminates.
Invoke-RunAsLoggedOnUser Runs a single command in the context of the logged-on user, from a PowerPack script that otherwise runs as SYSTEM.
Function What it does
$cs.Job_DisableLog Turns off logging for all subsequent calls, until $cs.Job_EnableLog is called.
$cs.Job_EnableLog Re-enables logging that was previously turned off with $cs.Job_DisableLog.
$cs.Job_RebootWS Marks that this PowerPack requires the workstation to reboot afterwards.
$cs.Job_Start Initializes the job/log context for the running script — sets up logging and related state for the package/version/action being processed.
$cs.Job_WriteLog Writes a line of text to the PowerPack log.
$cs.Log_SectionHeader Writes a decorative bordered section-header block into the log, to visually separate a group of related log entries.
Function What it does
$cs.File_AppendToFile Appends text as a new line to the end of file.
$cs.File_CopyFile Copies source to destination.
$cs.File_CopyTree Recursively copies a directory tree from source to destination, creating destination if it doesn’t exist.
$cs.File_CreateDirectory Creates the directory at path, including any missing parent directories, if it doesn’t already exist.
$cs.File_DelEmptyFolder Deletes the folder at path, but only if it is completely empty.
$cs.File_DeleteLineInFile Removes line(s) containing text from file.
$cs.File_DelFile Deletes a file.
$cs.File_DelTree Recursively deletes the directory at path and everything under it.
$cs.File_ExistDir Checks whether a directory exists.
$cs.File_ExistFile Checks whether a file exists.
$cs.File_FindFile Searches for files matching a name or wildcard pattern starting at searchroot, and returns the full paths of every match.
$cs.File_GetFileVersion Reads the FileVersion from a file’s version resource.
$cs.File_GetFolderSize Calculates the total size, in bytes, of every file under path, including all subfolders.
$cs.File_GetProductVersion Reads the ProductVersion from a file’s version resource.
$cs.File_RenameDir Renames or moves a directory.
$cs.File_RenameFile Renames or moves a file.
Function What it does
$cs.Ini_ReadEntry Reads a value from a classic INI file.
$cs.Ini_WriteEntry Writes or updates a value in an INI file’s section.
Function What it does
$cs.Reg_CreateKey Creates a registry key at the given path, automatically creating any missing parent keys along the way.
$cs.Reg_DeleteVariable Deletes a single named value from a registry key, leaving the key itself in place.
$cs.Reg_DelTree Recursively deletes a registry key and everything under it (subkeys and values).
$cs.Reg_EnumKey Returns the names of the subkeys found directly under a registry key.
$cs.Reg_ExistKey Checks whether a registry key exists.
$cs.Reg_ExistVariable Checks whether a named value exists under a registry key.
$cs.Reg_GetExpandString Reads a REG_EXPAND_SZ registry value and returns it with environment variables expanded.
$cs.Reg_GetInteger Reads a numeric (DWORD/QWORD) registry value.
$cs.Reg_GetMultiString Reads a REG_MULTI_SZ (multi-string) registry value.
$cs.Reg_GetString Reads a REG_SZ (string) registry value.
$cs.Reg_SetDword Writes a 32-bit REG_DWORD registry value.
$cs.Reg_SetExpandString Writes a REG_EXPAND_SZ registry value (a string containing unexpanded environment-variable references such as %SystemRoot%).
$cs.Reg_SetInteger Writes a 32-bit REG_DWORD registry value.
$cs.Reg_SetQword Writes a 64-bit REG_QWORD registry value.
$cs.Reg_SetString Writes a REG_SZ (string) registry value.
Function What it does
$cs.Service_Exist Checks whether a service with the given name is registered on the system, by looking for its key under the SYSTEM\CurrentControlSet\Services registry path.
$cs.Service_Start Starts the named service and waits up to maxTimeout milliseconds for it to reach the Running state.
$cs.Service_Stop Stops the named service and waits up to maxTimeout milliseconds for it to reach the Stopped state.
Function What it does
$cs.Shell_Execute Executes a command with optional arguments and returns its exit code.
$cs.Shell_ExecuteWithTimeout Executes a command and waits for it, like $cs.Shell_Execute, but forcibly kills the process if it hasn’t exited within timeout seconds.
$cs.Sys_ExistProcess Checks whether a process with the given name is currently running.
$cs.Sys_GetFreeDiskSpace Returns the amount of free disk space, in megabytes, on the specified drive.
$cs.Sys_IsMinimumRequiredDiskspaceAvailable Checks whether the specified drive has more free space than a required minimum.
$cs.Sys_isUserLoggedOn Checks whether a user is currently logged on to the computer, in any session.
$cs.Sys_KillProcess Kills every running process whose name contains processname as a substring (case-insensitive), not just an exact match — for example “chrome” would also match and kill a.
$cs.Sys_Sleep Pauses script execution for the given number of seconds.
$cs.Sys_WaitForProcess Waits for an already-running process to exit, checking every IntervalSec seconds up to a total of MaxWaitSec seconds.
$cs.Sys_WaitForProcessToExist Waits for a process to appear/start, checking every IntervalSec seconds up to a total of MaxWaitSec seconds.
Function What it does
$cs.MSI_GetProductCodeFromMSI Extracts and returns the ProductCode GUID embedded in an MSI file’s own metadata, without installing anything.
$cs.MSI_GetPropertiesFromMSI Reads several named properties from an MSI file at once.
$cs.MSI_GetPropertyFromMSI Reads a single named property (e.g. “ProductVersion”, “ProductName”, “Manufacturer”, “ProductCode”) from an MSI file’s internal property table.
$cs.MSI_IsMSIFileInstalled Convenience check that extracts the ProductCode from msifile and checks whether a product with that code is currently installed on the machine.
$cs.MSI_IsMSIGuidInstalled Checks whether a product with the given ProductCode GUID is currently installed, by querying Windows Installer’s product state directly — no MSI file needed, just the GUID.
Function What it does
$cs.UsrMgr_AddUserToLocalGroup Adds a local user account to a local group.
$cs.UsrMgr_ChangePassword Changes the password of a local user account.
$cs.UsrMgr_CreateLocalUser Creates a local user account.
$cs.UsrMgr_DeleteLocalUserAccount Deletes a local user account.
$cs.UsrMgr_EnumMembersOfLocalGroup Returns the members of a local group.
$cs.UsrMgr_ExistLocalUserAccount Checks whether a local user account exists.
$cs.UsrMgr_GetNameBySid Resolves a Windows SID to its account name, e.g. DOMAIN\username or BUILTIN\Administrators.
$cs.UsrMgr_RemoveUserFromLocalGroup Removes domain\userName from a local group.
Function What it does
$cs.CustomInventory_GetCategory Returns all instances of a custom inventory category with their values, as an ordered dictionary.
$cs.CustomInventory_GetCategoryNames Returns the names of the custom inventory categories on the device.
$cs.CustomInventory_GetInstance Returns all values of a custom inventory instance as an ordered dictionary.
$cs.CustomInventory_GetInstanceNames Returns the names of the instances in a custom inventory category.
$cs.CustomInventory_GetValue Reads a custom inventory value without its unit.
$cs.CustomInventory_RemoveCategory Removes a custom inventory category with all its instances and values.
$cs.CustomInventory_RemoveInstance Removes a custom inventory instance with all its values, and the category when it has no instances left.
$cs.CustomInventory_RemoveValue Removes a custom inventory value.
$cs.CustomInventory_SetValue Writes a custom inventory value for CapaOne, optionally with a unit such as bytes or date.
Function What it does
$InputObject.CloseMessageBox Closes a MessageBox That was created as async, and is not needed any longer.
$InputObject.ShowMessageBox Shows a MessageBox to the logged on user.