Let’s learn to Create Script Deployment Type using PowerShell for the SCCM EXE Application. Let’s see how to Deploy SCCM EXE Application using PowerShell.
In this post, I will create an SCCM (aka ConfigMgr) Application using Notepad ++ EXE Installer and deploy it to a device collection without using the SCCM Console. This is the PowerShell way of performing app creation, content distribution, and deployment.
I published the Create SCCM Application Deployment using the PowerShell guide already. I used MSI Installer to provide a better understanding of app deployment in that post. I will guide you on how to create a script deployment type using PowerShell for the SCCM EXE Application.
SCCM PowerShell cmdlets help admins to automate the package creation and deployment process. This post helps the PowerShell enthusiast to start working on a PowerShell scripting solution to create and deploy SCCM Application using EXE.
I have downloaded the 64-bit version of Notepad ++ from Download Notepad++ v8.4.1 | Notepad++ (notepad-plus-plus.org) and copied it to the shared folder of my SCCM site server.
Read more -> To understand 3 Best Methods to Import SCCM PowerShell Module Cmdlets
- Create SCCM Package Deployment using PowerShell
- SCCM Configuration Manager Application Creation Deployment Installation
Create SCCM Application Using PowerShell Cmdlets
Before creating the script deployment type, you need to create an SCCM Application using PowerShell. You will need to connect to the SCCM PowerShell drive. First, we have to connect to the SCCM site server via PowerShell.
I have separated each function of the SCCM Application creation (EXE) process into different sections and separate PowerShell commands for easy understanding. Later, it won’t be difficult to create one PowerShell command to cover end-to-end processes from package creation to monitoring.
In the SCCM Console, Click on the Drop-Down option on the top left side corner of the console and click on Connect via Windows PowerShell option.
Click on A on the following warning about the untrusted publisher.
Do you want to run software from this untrusted publisher?
File F:\Program Files\Microsoft Configuration Manager\AdminConsole\bin\Microsoft.ConfigurationManagement.PowerShell.Types.ps1xml is published by CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help (default is “D”): A
The New-CMApplication cmdlet creates an SCCM Application using PowerShell. A Configuration Manager application defines the metadata about the application.
To create an application, type the following PowerShell command and Press Enter.
New-CMApplication -Name "Notepad++_x64" -Description "Notepad++ x64 is a text and source code editor" -Publisher Notepad++ -SoftwareVersion 8.4.1 -IconLocationFile "\\<Name-of-the-SCCM-Server>\Sources\Test\Notepad++\icon.ico"
This command creates an SCCM Application named Notepad++x64 along with the following PowerShell parameters:
- Name: Provide the Name of the Package (For Example, Notepad++x64 )
- Description: Adds a description to the Application (Notepad++ is a text and source code editor)
- Publisher: Specifies the Publisher (Notepad++)
- SoftwareVersion: Specifies the version (8.4.1)
- IconLocationFile: Specifies the file for the Application icon. (For Example, <Name-of-the-SCCM-Server>\Sources\Test\Notepad++\Icon.ico)
- SCCM Application Supported Deployment Types | ConfigMgr | Endpoint Manager
- Implicit Uninstall Of An Application Using SCCM Remove Device From Collection
The Notepad++_x64 Application now appears in the Applications node of the Configuration Manager console.
- Select the Application from the list to validate the information.
- Right-click on the Application and select Properties.
Here you can see the details in the general tab and Software Center tab specified during the Application creation process.
The Notepad++ icon appears in the Software Center tab as mentioned in the command.
The New-CMApplication PowerShell cmdlet only supports JPG, JEPG, ICO, and PNG extensions. I tried with EXE, and it prompted me with the following error. Therefore, I used the Icon.ico file.
WARNING: The extension of the icon file is not valid. This cmdlet supports only JPG, JPEG, ICO, and PNG extensions.
Create Script Deployment Type Using PowerShell for SCCM EXE Application
Using the PowerShell commands below, let’s follow the steps to create a new Script deployment type for an existing Application.
Detection Method Clause: We can specify a single or an array of detection method clauses for this deployment type depending on the scenario. To create a detection clause, one of the following cmdlets is used:
Firstly, let’s create the detection Clause. For our example, I will use New-CMDetectionClauseRegistryKeyValue as the registry key value to check the existence of Notepad++.
New-CMDetectionClauseRegistryKeyValue creates a clause in a detection method on an application. This clause is a rule for a registry key value to indicate the presence of an application.
$clause = New-CMDetectionClauseRegistryKeyValue -Hive LocalMachine -KeyName 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++' -PropertyType Version -ValueName 'DisplayVersion' -Value -ExpectedValue '8.4.1' -ExpressionOperator GreaterEquals
The above PowerShell command creates a clause ($Clause) to compare the version of Notepad++ in the registry to be greater than or equal to 8.4.1 along with the following parameters:
- Hive: Specifies the registry hive where the key exists (For example, LocalMachine)
- KeyName: Specifies the name of the registry key that must exist to indicate the presence of the application.(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++)
- PropertyType: Specifies the data type of the registry key value (Version)
- ValueName: Specifies the registry key value that indicates the presence of the application(DisplayVersion)
- Value: Specifies registry key must satisfy the rule to indicate the presence of the application. Value key is used with PropertyType, ExpectedValue, ExpressionOperator.
- ExpectedValue: Specifies the value to compare against the registry key value(8.4.1)
- ExpressionOperator: Specifies the operator to compare the registry key value with the expected value.(GreaterEquals)
Now, let’s store the source file location of Notepad++ in a variable called $contentpath
$contentpath = '\\<Name-of-the-SCCM-Server>\Sources\Test\Notepad++'
Now, let’s create the Script Deployment Type for Notepad++ Application
Add-CMScriptDeploymentType cmdlet adds a Script Installer deployment type to an application. This deployment type can be a script or a program that installs content or does an action. This deployment type is used for setup.exe installers or script wrappers.
Add-CMScriptDeploymentType -ApplicationName Notepad++_x64 -DeploymentTypeName DT_Script_Npp -InstallCommand 'npp.8.4.1.Installer.x64.exe /S' -UninstallCommand '%ProgramFiles%\Notepad++\uninstall.exe /S' -AddDetectionClause $clause -ContentLocation $ContentPath -InstallationBehaviorType InstallForSystem -EstimatedRuntimeMins 10 -LogonRequirementType WhetherOrNotUserLoggedOn
The above PowerShell command creates and adds the script deployment type named DT_Script_Npp to the application named Notepad++_x64 along with the following parameters:
- ApplicationName: Specifies the name of the application for this deployment type. (For example, Notepad++_x64)
- DeploymentTypeName: Specifies a display name for this deployment type. (For example, DT_Script_Npp )
- InstallCommand: Specify the installation program command line to install this application. (npp.8.4.1.Installer.x64.exe /S)
- UninstallCommand: Specifies the command line to uninstall the application(%ProgramFiles%\Notepad++\uninstall.exe /S)
- AddDetectionClause: Specifies an array of detection method clauses for this deployment type.( $clause)
- ContentLocation: Specifies the network source path of the content.($contentpath)
- InstallationBehaviorType: Specifies the installation behavior for this deployment type(InstallForSystem)
- EstimatedRuntimeMins: Specifies the estimated installation time, in minutes, of this deployment type for the application (10)
- LogonRequirementType: Specifies the requirement for a signed-in user.(WhetherOrNotUserLoggedOn)
The DT_Script_Npp Deployment type now appears in the Applications node of the Configuration Manager console.
Select the Deployment Type DT_Script_Npp to validate the information. Right-click on the DT_Script_Npp and select Properties.
Here you can see the Deployment Type settings in the General, Content, Programs, Detection Method, User Experience, Requirements, Return Codes, Dependencies tab specified during the Application creation process.
In the Content tab, you can verify the content location.
In the Programs tab, you can verify the Installation program and uninstall the program.
In the Detection Method tab, you can verify the Detection method used to detect the presence of the Application on the target machine.
In the Detection Method tab, by clicking on Edit Clause, you can verify the Detection rules used to detect the presence of the Application on the target machine.
Similarly, in the User Experience Tab, you can verify the Installation behavior, logon requirement, Installation program visibility, and Estimated Installation time.
Once you validate the information added to the Deployment Type properties, you can close the Applications wizard and proceed next to prepare for distribution and deployment.
Distribute EXE Application Content to Distribution Point using PowerShell
The following steps help you distribute content to distribution points using the PowerShell command.
The Start-CMContentDistribution cmdlet distributes content from the content library on the site server to distribution points. You can also use the cmdlet to distribute content for the SCCM Objects –
- Legacy packages
- Software update deployment packages
- Driver packages
- OS images
- OS upgrade packages
- Boot images
- Content referenced by task sequences
Note – The content can be distributed to distribution points, distribution point groups, or collections associated with distribution point groups.
The next step is to distribute the content of the Notepad++_x64 Application to the Distribution Point, Type and Enter the following command:
Start-CMContentDistribution -ApplicationName "Notepad++_x64" -DistributionPointName '<Name-of-the-SCCM-Server>'
The command distributes the Notepad++_64 Application to a specified Distribution Point along with the following parameters:
- ApplicationName: Provide the Name of the Application
- DistributionPointName: Specifies the Distribution Point where the Package content will be distributed
Once the content is processed to distribute, You can monitor the content status. If it’s showing the yellow color, distribution is in progress.
SCCM EXE Application Deployment using PowerShell
The New-CMApplicationDeployment cmdlet deploys the application to resources in a collection. The collection can specify the collection parameter of the PowerShell command by ID or name.
Type the following command and press Enter to deploy the NotePad++_x64 Application to a collection.
New-CMApplicationDeployment -ApplicationName "Notepad++_x64" -CollectionName "Test_Collection" -DeployAction Install -DeadlineDateTime (get-date) -DeployPurpose Required -UserNotification DisplayAll
The command distributes the Notepad++_x64 Application to a specified Distribution Point along with the following parameters:
- ApplicationName: Provide the Name of the Application (Notepad++_x64)
- CollectionName: Specifies the Collection Name where the Application will be deployed (Test_Collection)
- DeployAction: Specifies the deployment action (Install)
- DeadlineDateTime: Specifies a DateTime object for when this deployment is assigned, also known as the deadline. To get this object, the Get-Date built-in cmdlet is used. (The
Get-Datecmdlet gets a DateTime object that represents the current date or a date that you specify)
- DeployPurpose: Specifies the Deployment Purpose. (Required)
- UserNotification: Specifies the type of user notification (DisplayAll)
Initiate Machine Policy Request & Evaluation Cycle using PowerShell
Here’s how on the client computer, Initiate the Machine Policy Request & Evaluation Cycle to speed up the inventory using PowerShell, SCCM client action Machine Policy Request & Evaluation Cycle “immediately” trigger the re-evaluation of the machine policy process from Windows 10 client.
The Invoke-CMClientAction cmdlet sends a notification to client computers to trigger an immediate client action. The notification can be sent to one or multiple client computers or all the computers in a specified device collection.
To trigger the machine Policy Retrieval and Evaluation cycle on the client machine, type command and press Enter:
Invoke-CMClientNotification -DeviceName TEST_Machine -ActionType ClientNotificationRequestMachinePolicyNow
Monitor SCCM Application Deployment Status using PowerShell
The Get-CMApplicationDeploymentStatus cmdlet gets the status of SCCM Application Deployment Status.
Get-CMApplicationDeployment cmdlet gets an object for application deployment. This object is used to configure or remove the deployment.
Let’s Monitor SCCM Application Deployment Status using PowerShell. Now, to check the status of the Notepad++_x64 Application deployment, type the PS command:
$a=Get-CMApplicationDeployment -Name 'Notepad++_x64'
Get-CMApplicationDeploymentStatus -InputObject $a
This command gets the status of the Application named Notepad++_x64 that is deployed to SCCM clients.
We can verify the enforcement state for the Notepad++_x64,DeploymentType DT_Script_Npp. EnforcementState 1000 means Installation is Successful on the Target collection.
Importance of Get-CMApplicationDeploymentStatus Cmdlet: It provides all the details ( AppName, AssignmentID, AssignmentUniqueID, CollectioID, CollectionName, DTName, EnforcementState etc.) which you will need later to manage, modify, remove the Deployment, Application, DeploymentType)
List of Useful PowerShell Commands to Manage SCCM Application Deployment
Let’s check the List of Useful PowerShell Commands to Manage SCCM Application Deployment.
The following is the PS command to modify an SCCM Application Deployment Type.
Set-CMScriptDeploymentType -ApplicationName "Notepad++_x64" -DeploymentTypeName "DT_Script_Npp" -Comment "Script updated to uninstall" -UninstallCommand 'uninstall.exe /S'
PS command to add detection method to SCCM Application Deployment Type.
These commands add a File detection Clause for Notepad++ to the Deployment Type. This detection method will look for uninstall.exe in the location %ProgramFiles%\Notepad++ and compare the file size to 267538 bytes.
$clauseFile2 = New-CMDetectionClauseFile -FileName "uninstall.exe" -Path "%ProgramFiles%\Notepad++" -PropertyType Size -ExpectedValue 267538 -ExpressionOperator IsEquals -Value
Set-CMScriptDeploymentType -ApplicationName "Notepad++_x64" -DeploymentTypeName "DT_Script_Npp" -AddDetectionClause $clauseFile2
Dhanraj Barman, I have been working in IT Infrastructure implementation, deployment, and Maintenance for more than 6 years. I am good at using Enterprise tools – ConfigMgr | Microsoft Endpoint Configuration Manager (MECM) | SCCM, Operating System Deployment (OSD) -Microsoft Deployment Toolkit (MDT) – Standalone, MDT integration with SCCM, Patch Management using WSUS & SCCM. I am improving my skillsets in Mobile Device Management (Microsoft Intune) and Autopilot, and Cloud-based deployment solutions. Recently I have started working on the latest product called Tanium. It’s a product deployment Management & provisioning tool for Windows & Linux.