# $cs.Shell_Execute

> Executes a command with optional arguments and returns its exit code.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-shell-execute/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Executes a command with optional arguments and returns its exit code. Use this instead of `Start-Process` for running installers and other external commands from a PowerPack — it's the standard way to run an MSI/EXE and capture its result.

### Syntax

$cs.Shell\_Execute(string command, string arguments = "", bool wait = true, int windowstyle = 0, bool mustexist = false, string workingdirectory = "")

### Parameters

#### command (String)

Command to execute.

#### arguments (String)

Arguments for the command. Default is empty.

#### wait (Boolean)

Wait for the command to complete before returning. Default is `$true`. If `$false`, the process is started asynchronously and `0` is returned immediately.

#### windowstyle (Int32)

Window style for the command: `0`=hidden, `1`=normal, `2`=minimized, `3`=maximized. Default is `0` (hidden).

#### mustexist (Boolean)

Check that `command` exists before executing; returns `5` without running anything if it doesn't. Default is `$false`.

#### workingdirectory (String)

Working directory for the command. Default is empty.

### Return value

Integer. The process's exit code if `wait=$true`, or `0` immediately if `wait=$false`.

### Example

**PowerShell**

```powershell
$cs.Shell_Execute("msiexec.exe", "/i `"$Packageroot\kit\GoogleChromeStandaloneEnterprise64.Msi`" /QN REBOOT=REALLYSUPPRESS ALLUSERS=1")
```

Install an MSI with the log written to `$global:AppLogFolder`, so it's automatically uploaded and visible in the CapaInstaller Console:

```powershell
$MsiPath = Join-Path $global:Packageroot "kit" "7zip.msi"
$LogPath = Join-Path $global:AppLogFolder "7zip_Install.log"
$Arguments = "/i `"$MsiPath`" /qn /norestart /log `"$LogPath`""

$Result = $cs.Shell_Execute("msiexec.exe", $Arguments)
if ($Result -ne 0 -and $Result -ne 3010) {
  $cs.Job_WriteLog("7-Zip installation failed with exit code: $Result")
  Exit-PSScript $Result
}
```

Run an EXE from the kit folder with `mustexist=$true` so a missing installer fails fast with a clear exit code instead of a confusing native error, and a specific working directory:

```powershell
$SetupExe = Join-Path $global:Packageroot "kit" "setup.exe"
$Result = $cs.Shell_Execute($SetupExe, "/S /v/qn", $true, 0, $true, (Join-Path $global:Packageroot "kit"))
if ($Result -eq 5) {
  Exit-PSScript -exitcode 1 -exitmessage "setup.exe was not found in the kit folder"
} elseif ($Result -ne 0) {
  $cs.Job_WriteLog("Installation failed with exit code: $Result")
  Exit-PSScript $Result
}
```

### Related functions

[$cs.Shell_ExecuteWithTimeout](/capainstaller/powerpacks/cs-shell-executewithtimeout/)
