Hi there! Have you ever scratched your head and wondered if you loaded software the right way? You’re not by yourself. This gives a lot of system administrators a headache. This is especially hard to do when handling programs like AutoCAD 2022 in a variety of settings. That is where Microsoft Intune really shines. The fact that you can use your own recognition scripts makes it very useful. A custom Intune detection script is key.

These scripts save my life a lot. They help you check every network gadget. This makes sure that not only is there an app, but it’s also the right version for you. Today, we’re going to look in detail at a PowerShell script that can find AutoCAD 2022. This guide will help make your business life a little easier, no matter how much you know about Intune or how new you are to it. Allow us to begin on our Intune detection script!

How do I make a Intune Detection Script?

First, what does a custom Intune recognition script really mean? It’s just a script for your control tool for Microsoft Intune. It checks automatically to make sure that all of your devices have the same version of software loaded. What makes this cool? Because it takes care of one of the most boring jobs in IT management automatically. Imagine making sure that software is compliant and installations are correct without having to check each machine by hand. Not interested!

PowerShell is used to make custom scripts like the one we’re talking about today. It is a strong programming language that can do a lot with just a few lines of code. These scripts can get into the Windows Registry, find loaded programs, and check out different versions of installed programs. It’s not just about saving time; it’s also about making sure that your software deployments work well and stay stable. We all hate those crazy support calls, but this cuts down on them.

The Breakdown

Getting into the nitty-gritty of our PowerShell script, let’s break it down line by line. This will help you understand exactly what each part does. Let’s get our geek on!

The Script

$ProductName = "AutoCAD 2022"
$ProductVersion = "24.1.173.0"
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$apps = Get-ChildItem -Path $RegPath 
$Test = foreach ($app in $apps) {
    $app | Get-ItemProperty | Where-Object {($_.DisplayName -like "$ProductName")} | select-object *
}
if ($Test.displayversion -ge "$ProductVersion") {
    write-host "Installed - $($test.DisplayVersion)"
    exit 0
} else {
    exit 1
}

Lets go line by line in our Intune Detection script and break it down.

Line 1-2: Define the Product

These two lines allow you to define the product you want to search for and the Version you wish to check for. The product name can take wild cards, but I don’t suggest it as it can cause more conflicts than be helpful.

$ProductName = "AutoCAD 2022"
$ProductVersion = "24.1.173.0"

Line 3: Setting the Registry Path

The next line is where we look in the registry for the uninstall strings and product information. These registry keys is what win32_product looks at to get information. Thus, it’s much faster than using the win32_product.

$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

Line 4: Gather Installed Applications

Here, we’re grabbing a list of all items in the paths defined earlier. It’s akin to gathering all the potential treasure chests. We will use these magical coins later to get what we need.

$apps = Get-ChildItem -Path $RegPath

Lines 5 – 7: filter and test for the product

In these lines, we loop through each app and check if it matches our product name. If it does, we take a closer look at its properties. Here we are checking for our gold coins vs the silver coins. We take each of the products we want, and put it into our test varaible, or chest.

$Test = foreach ($app in $apps) {
    $app | Get-ItemProperty | Where-Object {($_.DisplayName -like "$ProductName")} | select-object *
}

Lines 8-12: Check Version and Provide Output

Assuming you have chosen a name that will only show up once, we now check to see if the version matches up. If it does, then we say, yep, it’s installed and exit with a code of ZERO, the big 0. If it doesn’t, then we exit with the error code of 1. This is important as Intune is looking for a string and an error code of 0 for success.

if ($Test.displayversion -ge "$ProductVersion") {
    write-host "Installed - $($test.DisplayVersion)"
    exit 0
} else {
    exit 1
}

To Deploy Your Script with Intune

Intune’s custom detection script deployment requires more than copying and pasting code. Ensure the script operates smoothly on all targeted devices. Step-by-step instructions:

  1. The first step in script preparation is to test it locally. You shouldn’t distribute something without testing on your own machines.
  2. Put the script in Intune:
    • Enter the Microsoft Endpoint Manager admin center.
    • Select Windows 10 under Devices > Scripts > Add.
    • PowerShell script upload and settings. This involves choosing a system or user context for the script based on access level.
  3. Assign script:
    • After uploading your script, assign it to device groups. You can choose groups by organizational units or other deployment parameters.
  4. Monitor script deployment:
    • Monitor script execution on the script profile’s Device Status and User Status tabs after deployment. This shows if the script is executing properly or if any devices are failing.
  5. Update as needed:
    • Monitoring feedback may need script or deployment parameters changes. Maintaining compatibility with new system updates or IT environment changes may need regular updates.

Effective script deployment guarantees that all network devices meet software standards. Assuring all machine parts are well-oiled and working together.

    Common Issues and Troubleshooting Tips for a Intune Detection Script

    Even with the best preparation, things might not always go as planned. Here are some common issues you might face with custom Intune scripts and how to troubleshoot them:

    1. Script Fails to Execute:
      • Check Execution Policy: Ensure that the script’s execution policy allows it to run. This policy can sometimes block scripts if not set to an appropriate level.
      • Review Script Permissions: Make sure the script has the necessary permissions to access the registry paths or any other resources it uses.
    2. Incorrect Script Output:
      • Verify Script Logic: Double-check your script’s logic. Look for typos in variable names or incorrect operators in conditions.
      • Test Locally: Always run the script locally on a test machine before deploying it to avoid simple errors.
    3. Issues with Script Deployment:
      • Assignment Errors: Make sure the script is assigned to the correct device groups. Incorrect assignments can lead to the script not being run where it’s needed.
      • Check Intune Logs: Use the logs provided by Intune to identify what’s going wrong when the script runs.

    Troubleshooting is an integral part of managing scripts in a large environment. It’s a little like detective work, where you need to keep a keen eye on clues and sometimes think outside the box.

    What can we learn as a person today?

    Even though we don’t always mean it that way, we frequently execute “scripts” in our day-to-day lives, much like a PowerShell script checks for certain conditions before proclaiming success or failure. These are the things we do on a regular basis without thinking, like automated checks on a computer system; they help us evaluate and respond to the many opportunities and threats that life presents.

    When we look for patterns in our own lives, we can see what’s working and what isn’t. By exercising first thing in the morning, for instance, you may find that you get more done that day. This would be an example of a positive pattern, like a script that verifies everything is going according to plan. In contrast, if you find yourself feeling low after a session of social networking, it’s a sign that something needs to be changed, similar to a script fault.

    It is essential to listen to environmental feedback in order to make modifications. Our emotional and physiological responses, the opinions of others around us, and the outcomes we attain can all serve as sources of this type of feedback. Like adjusting a screenplay that isn’t working as planned, when our life’s routines bring about less ideal consequences, it’s a warning to halt and re-calibrate. Perhaps it necessitates reevaluating our current habits and deciding how much time is best spent on specific pursuits.

    The idea is to embrace learning and refining as a process, just like scripts that are updated over time. There is no instruction manual for life, and sometimes the only way to learn is by making mistakes. Being self-aware and willing to make adjustments for the better is more important than striving for perfection.

    Additional Resources