> For the complete documentation index, see [llms.txt](https://documentation.2pintsoftware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.2pintsoftware.com/deployr/automation-and-powershell/scripting-for-deployr-server/automating-content-item-creation/generate-application-content-items.md).

# Generate Application Content Items

Using PowerShell is a convenient way to automate the creation of application content items and save time compared with using the dashboard. Creating content items with PowerShell involves several steps: first, create the content item shell, then create a version within it. Note that this is different from importing a content item exported from another DeployR server: this creates a completely new content item from scratch.

You will use several DeployR functions:

* Get-DeployRApplication
* New-DeployRContentItem
* New-DeployRContentItemVersion

This example creates a 7-Zip application content item.\
I have downloaded the 7-Zip MSI to my source folder. I will define the MSI path and installation command line as variables.\
\
First, create the content item shell. Once it is created, it appears in the dashboard.

{% hint style="info" %}
Note: any time you use the DeployR functions, you need to import the module and connect to DeployR, as described on the [Scripting for DeployR Server](/deployr/automation-and-powershell/scripting-for-deployr-server.md) page.
{% endhint %}

<pre class="language-ps1"><code class="lang-ps1"><strong>$AppName = '7zip'
</strong>$NewDRCI = New-DeployRContentItem -Type Folder -Name $AppName -Description "Script Generated" -Purpose Application
</code></pre>

After creating the content item shell, populate the version with the following details:

```ps1
$AppSourceFolder = 'D:\DeployRSources\Applications\7-Zip\26.00'
$AppDescription = '26.00'
$InstallationCommandLine = 'msiexec.exe /i "7z2600-x64.msi" /quiet /norestart'
New-DeployRContentItemVersion -ContentItemId $NewDRCI.id -SourceFolder $AppSourceFolder -InstallationCommandLine $InstallationCommandLine -Description $AppDescription
```

Overall, it is pretty straightforward to create an Application Content Item in DeployR. Once you know the basics, you can do more. I have created several functions to simplify automation of generating these applications. These functions are:

* New-DeployRApp
  * This is used for creating a brand new app
* Test-DeployRAppExists
  * Used in automation to check whether an app you are about to generate already exists.
* Update-DeployRApp
  * Used to update an app already in DeployR by adding a new version

```powershell
#Function to Create New Apps in DeployR
Function New-DeployRApp {
    Param (
        [string]$AppName,
        [string]$AppSourceFolder,
        [string]$AppDescription = "No Description Provided",
        [string]$InstallationCommandLine = ""
    )

    $NewDRCI = New-DeployRContentItem -Type Folder -Name $AppName -Description "Script Generated" -Purpose Application
    New-DeployRContentItemVersion -ContentItemId $NewDRCI.id -SourceFolder $AppSourceFolder -InstallationCommandLine $InstallationCommandLine -Description $AppDescription
}

#Function to Test if App is already in DeployR
Function Test-DeployRAppExists {
    Param (
        [string]$AppName,
        [string]$AppVersion,
        [Parameter(Mandatory=$false)]
        [PSObject[]]$AllApps
    )

    # Use provided AllApps collection if available, otherwise query DeployR
    if ($null -eq $AllApps -or $AllApps.Count -eq 0) {
        $AllApps = Get-DeployRApplication
    }

    $existingApp = $AllApps | Where-Object { $_.Name -eq $AppName } -ErrorAction SilentlyContinue
    if ($null -ne $existingApp) {
        $LatestVersion = ($existingApp.versions | Select-Object -ExpandProperty Description | Sort-Object -Descending | Select-Object -First 1)
        return [PSCustomObject]@{
            Name          = $existingApp.Name
            LatestVersion = $LatestVersion
        }
    } else {
        return $false
    }
}

##Function to Update App in DeployR by adding new Version (Append new version number)
Function Update-DeployRApp {
    Param (
        [string]$AppName,
        [string]$AppVersion = "No Description Provided",
        [string]$AppSourceFolder,
        [string]$InstallationCommandLine = "",
        [Parameter(Mandatory=$false)]
        [PSObject[]]$AllApps
    )

    # Use provided AllApps collection if available, otherwise query DeployR
    if ($null -eq $AllApps -or $AllApps.Count -eq 0) {
        $existingApp = Get-DeployRApplication -Name $AppName -ErrorAction Stop
    } else {
        $existingApp = $AllApps | Where-Object { $_.Name -eq $AppName } -ErrorAction SilentlyContinue | Select-Object -First 1
    }
    
    if ($null -ne $existingApp) {
        Write-Host "Updating DeployR Application: $AppName"
        $NewDRCIV = New-DeployRContentItemVersion -ContentItemId $existingApp.id -SourceFolder $AppSourceFolder -InstallationCommandLine $InstallationCommandLine -Description $AppVersion
    } else {
        Write-Host "DeployR Application not found: $AppName"
    }
}

```

With these functions, I have automated creating and updating several applications in my DeployR lab. The full script is on the 2Pint Software GitHub: <https://github.com/2pintsoftware/2Pint-DeployR/blob/main/Automation/Generate-AppContentItems.ps1>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.2pintsoftware.com/deployr/automation-and-powershell/scripting-for-deployr-server/automating-content-item-creation/generate-application-content-items.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
