Skip to main content

Automation

With the SCCM Application Manager applications and packages can be created and deleted by scripts. In addition, status changes for applications and packages are also possible. Before this form of automation can be used, certain preparations must be made and certain requirements must be met.

  • Prerequisites and preparations
    There must be a vaild and automatic connection to the SCCM Site.
  • The license must be valid.
  • The maintenance mode must not be enabled.
  • A disabled or valid version control must be defined.
  • There must be sufficient SCCM permissions.
  • The SCCM Application Manager should be started by hand before automation. It must start without any restrictions and the connection to a site server must be established automatically. If necessary, the SCCM Application Manager must be configured, because the existing configuration files are used during automation.
Starting the automation process

During the automation process an XML file is passed to the SCCM Application Manager by parameter, which contains the instructions to be executed automatically. The call may look like this:

SCCMApplicationManager.exe C:\myFolder\myFile.xml

Now the SCCM Application Manager will be started without a graphical user interface and stopped, after the instructions have been executed.

Tip
If the statement SCCMApplicationManager.exe C:\myFolder\myFile.xml is specified within a command prompt, information, warnings, and error messages are transferred to this window.
sccm-automation.png

Structure of the XML file

The structure of an XML file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<!--
	A task must have one of the following actions: 
	CreateApplication
	CreatePackage
	SetApplicationState
	SetPackageState
	DeleteApplication
	DeletePackage
	-->
	<Task Action=""> 
	</Task>
</SCCMApplicationManager>

The individual work steps are devided in Tasks. Every task must have an Action attribute. The following values exist for the Action attribute:

  • CreateApplication (creates an application)
  • CreatePackage (creates a package)
  • SetApplicationState (sets the status of one or more applications)
  • SetPackageState (sets the status of one or more packages)
  • DeleteApplication (deletes one or more applications)
  • DeletePackage (deletes one or more packages)

Note
When using XML files please note that start and end tags, as well as attributes, are case sensitive (<Task /> is not the same as <task />).

SCCM Connections

Normally, automation uses the default connection to a SCCM site. This is the connection where the checkbox Auto Connect is enabled.

sccm-default-connection.png

If you want to use a different connection to a SCCM site, the GUID of such a connection can optionally be specified within the XML file. This GUID can be copied from the login dialog ...

sccm-connection-guid.png

... and inserted into the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager ConnectionGuid="d77da9b5-de21-45c8-bab2-acc3ec9e7426">
	<Task Action=""> 
	</Task>
</SCCMApplicationManager>

In this case, the ConnectionGuid attribute is added to the SCCMApplicationManager node and the value of the GUID is entered.

Note
If Connection GUIDs are used, they must be valid and the specified connection must exist and be established, as the default connection will not be used in the event of an error.

Creating applications or packages

At least the following XML file must exist to create applications or packages:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="CreateApplication"> <!-- or Action="CreatePackage" -->
		<SourceFile>\\myServer\myShare\myFile.msi</SourceFile>
	</Task>
</SCCMApplicationManager>

Action must be CreateApplication or CreatePackage. In addition, the node <SourceFile /> must contain the UNC path of the source file. Valid file extensions are: .cmd, .exe, .msi, .ps1 or .vbs.

The above spelling assumes that the values for Manufacturer, Product, Version, Language, and UninstallRegKey can be read automatically from the source file. However, this is only guaranteed for MSI files. Therefore, these values can also be specified.

Optionally, when creating applications, an <IconFile /> can be specified for display in the Software Center.

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="CreateApplication"> <!-- or Action="CreatePackage" -->
		<SourceFile>\\myServer\myShare\myFile.msi</SourceFile>
		<Manufacturer>myManufacturer</Manufacturer>
		<Product>myProduct</Product>
		<Version>0.0.0.0</Version>
		<Language>myLanguage</Language>
		<UninstallRegKey>myUninstallRegKey</UninstallRegKey>
		<IconFile>\\myServer\myShare\myIconFile.png</IconFile>
	</Task>
</SCCMApplicationManager>

In addition, the SCCM Application Manager also supports custom properties. Because these properties are not read out automatically they can be defined as follows (see examples of Syscode, Revision und SoftwareArchitecture):

More notes
When specifying custom properties, make sure that the correct spelling is used.

Any properties specified in a task may overwrite existing properties from the source file.

The source file must not be in the context of the PowerShell App Deployment Toolkit. PowerShell scripts are allowed.

Starting with version 2.9 of the SCCM Application Manager, different Collection Resource Types are supported. These determine whether collections for devices or users should be created during the creation of applications or packages. In this case, the optional attribute CollectionResourceType can be specified with . It can contain the values Device or User. If no information is specified, the default is Device.

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="CreateApplication" CollectionResourceType="User" > <!-- or CollectionResourceType="Device" -->
		<SourceFile>\\myServer\myShare\myFile.msi</SourceFile>
	</Task>
</SCCMApplicationManager>
Status change of Applications or packages

The status of applications or packages can be set in different ways:

  1. Direct: The status is explicitly set to Test, Approved, Retired, Obsolete or Failed.
  2. The status value is set to the next value (Forward) or to the previous (Back) value.

Important
Only the statuses of applications or packages that have previously been created with the SCCM Application Manager can be changed.

For applications, one or more <ModelName /> nodes can be specified when changing status (the corresponding values for this are available in the WMI class SMS_ApplicationLatest). Packages use one or more node <PackageID /> instead (see WMI class SMS_Package).

The Action attribute must be set to SetApplicationState for applications. For packages it must be set to SetPackageState.

The State attribute can take the values Test, Approved, Retired, Obsolete or Failed.

The Step attribute expects the values Forward or Back.

For the first variant the XML file for applications must look like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="SetApplicationState" State="Approved"> <!-- State can be Test, Approved, Retired, Obsolete or Failed -->
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_2334f04c-bd64-48f3-b14c-275c15d9cd67</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_ecb26fdc-1353-44f1-ac4d-553fd20de7cf</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_473f1e7c-9554-45d7-b01b-accc215c5587</ModelName>
	</Task>
</SCCMApplicationManager>

For the first variant the XML file for packages must look like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="SetPackageState" State="Approved"> <!-- State can be Test, Approved, Retired, Obsolete or Failed -->
		<PackageID>ABC00199</PackageID>
		<PackageID>ABC0019A</PackageID>
		<PackageID>ABC0019B</PackageID>
	</Task>
</SCCMApplicationManager>

For the second variant the XML file for applications must look like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="SetApplicationState" Step="Forward"> <!-- Step can be Forward or Back -->
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_2334f04c-bd64-48f3-b14c-275c15d9cd67</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_ecb26fdc-1353-44f1-ac4d-553fd20de7cf</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_473f1e7c-9554-45d7-b01b-accc215c5587</ModelName>
	</Task>
</SCCMApplicationManager>

For the second variant the XML file for packages must look like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="SetPackageState" Step="Forward"> <!-- Step can be Forward or Back -->
		<PackageID>ABC00199</PackageID>
		<PackageID>ABC0019A</PackageID>
		<PackageID>ABC0019B</PackageID>
	</Task>
</SCCMApplicationManager>
Deleting applications or packages

Important
Only applications or packages that were previously created with the SCCM Application Manager can be deleted.

For deleting applications, the value for Action is set to DeleteApplication and when deleting packages the value for Action is set to DeletePackage.

Wen deleting applications, one or more <ModelName /> nodes can be specified (the corresponding values for this are available in the WMI class SMS_ApplicationLatest). Packages use one or more node <PackageID /> instead (see WMI class SMS_Package).

The XML file for applications therefore looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="DeleteApplication">
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_2334f04c-bd64-48f3-b14c-275c15d9cd67</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_ecb26fdc-1353-44f1-ac4d-553fd20de7cf</ModelName>
		<ModelName>ScopeId_DCAA8452-EBBC-4535-A253-366403E5AA44/Application_473f1e7c-9554-45d7-b01b-accc215c5587</ModelName>
	</Task>
</SCCMApplicationManager>

For packages, this file is required:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="DeletePackage">
		<PackageID>ABC00199</PackageID>
		<PackageID>ABC0019A</PackageID>
		<PackageID>ABC0019B</PackageID>
	</Task>
</SCCMApplicationManager>
Multiple tasks in an XML file

Basically, multiple tasks within an XML file are supported. The creation of three applications can look like this:

<?xml version="1.0" encoding="utf-8" ?>
<SCCMApplicationManager>
	<Task Action="CreateApplication">
		<SourceFile>\\myServer\myShare\myFile1.msi</SourceFile>
	</Task>
	<Task Action="CreateApplication">
		<SourceFile>\\myServer\myShare\myFile2.msi</SourceFile>
	</Task>
	<Task Action="CreateApplication">
		<SourceFile>\\myServer\myShare\myFile3.msi</SourceFile>
	</Task>
</SCCMApplicationManager>

What seems practical at first glance can have disadvantages at second glance if an error occurs during the execution of the tasks. Depending on the severity, the entire operation cancels because it cannot continue, or only a few tasks are performed. In such scenarios, it is a good idea to read the log file.

Exit codes and log file

After running the SCCM Application Managers in automation mode, the following exit codes can be returned:

  • 0 = O.K.
  • 1 = Error

If an exit code of 1 is returned, the corrsponding error descriptions can be found in the SCCMApplicationManager.log file. It is located in the installation directory of the SCCM Application Manager. The log file has a format that can be read with the CMTrace.exe tool.