INTRODUCTION

Powershell methods, is there anything they can’t do? No, not really!
In this blog post I will explain how you can use Powershell Detection Methods in SCCM.

As with many other cases with Powershell, the options are endless.

MY SCENARIO

I came across a scenario at a customer where during an application installation, configuration files were to be replaced in the installation directory using a script. Since a configuration line was different in the different files, this had to be checked during the application detection after the installation.

The easy way out would have been to detect the existence of the configuration file, but I also wanted to make sure the content in the file was correct.

DETECTION METHODS

When configuring Detection Methods, you want the Detection Method to be as granular as possible.

Some out-of-the-box Detection Methods which work very well:

  • MSI
  • Registry keys
  • File version

Detection Methods are one of the main culprits when dealing with application deployment issues.

Sometimes the Detection Method is simply misconfigured and the SCCM client does not detect the application as installed, or a Detection Method is configured as non-granular.

An example of this is adding to a script that a text file is to be created and then use this text file for detecting if the application is installed. This is NOT a good way of configuring Detection Methods.

Read more about Powershell Detection Methods here: Microsoft Docs – Introduction to Application Management

POWERSHELL DETECTION METHODS

HOW THEY WORK

When creating Powershell Detection Methods in SCCM, you need to understatnd how they work. This includes understanding how the output of your Powershell Detection Method is intepreted by SCCM.

The below table from Microsoft Docs shows how script output defines the result:

Script exit codeData read from STDOUTData read from STDERRScript resultApplication detection state
0EmptyEmptySuccessNot installed
0EmptyNot emptyFailureUnknown
0Not emptyEmptySuccessInstalled
0Not emptyNot emptySuccessInstalled
Non-zero valueEmptyEmptyFailureUnknown
Non-zero valueEmptyNot emptyFailureUnknown
Non-zero valueNot emptyEmptyFailureUnknown
Non-zero valueNot emptyNot emptyFailureUnknown

SOLUTION

DESCRIPTION

This solution uses Powershell to parse a text file, which in my example is a configuration file. It will then return a result if the string is found.

You can use this solution as an example if you want to look for other strings in text files.

HOW-TO

STEP 1 – CREATE APPLICATION

Start by going to the Software Library and press Create Application.

Select Manually specify the application information.

Enter the information of the application.

Input any additional information about the application.

STEP 2 – CREATE DEPLOYMENT TYPE

On the next step, press Add to add a new Deployment Type.

Select Manually specify the deployment type information.

Enter the Nameof the Deployment Type. This can be anything.

Powershell detection methods

Enter the installation instructions of the application according to your requirements.

Powershell detection methods

STEP 3 – CREATE DETECTION METHOD

Now we are the main subject of this blog post, namely the Powershell Detection Method.

Select Use a custom script to detect the presence of the deployment type. Press Edit.

Powershell detection methods
MODIFY THE SCRIPT

Modify the below script to suit your needs. The example below will look strings in 3 different files. You will need to make the following modifications:

  • String variables
  • String<number>Location variables

Change Script type to Powershell and enter the code below this screenshot in the text box. You will of course need to modify it to suit your needs

Powershell detection methods
THE CODE

STEP 4 – FINALIZE APPLICATION

Once you have added the Detection Method, you will need to go through the rest of the wizard to finalize the prcess.

STEP 5 – DISTRIBUTE & DEPLOY

End by Distributing and Deploying the application to users or devices, depending on your environment.

SUMMARY

Powershell Detection Methods are powerful to use when you cannot use the default MSI, registry or file version detections. They are however a bit more complex and getting your head around how the return logic of the script work might take some time.

For all scenarios when you can use a built-in Detection Method, use that, but in all other custom cases you can use Powershell Detection Methods.

REFERENCES

RELATED POSTS