Failed Remediation Script in Intune while “Run Script 64-bit PowerShell” Option is Turned On? Here’s the Fix!
Image by Armida - hkhazo.biz.id

Failed Remediation Script in Intune while “Run Script 64-bit PowerShell” Option is Turned On? Here’s the Fix!

Posted on

If you’re reading this, chances are you’re frustrated with Intune’s remediation script failing to execute while the “Run script 64-bit PowerShell” option is enabled. Don’t worry, you’re not alone! In this article, we’ll dive into the reasons behind this issue and provide you with a step-by-step guide to resolve it.

The Culprit: 32-bit PowerShell vs. 64-bit PowerShell

When you enable the “Run script 64-bit PowerShell” option in Intune, the script is executed in the 64-bit PowerShell environment. However, some scripts might be written to run in the 32-bit PowerShell environment, which can lead to conflicts and ultimately, failure.

So, what’s the difference between 32-bit and 64-bit PowerShell?

  • 32-bit PowerShell: This environment is designed for 32-bit systems and is limited to accessing 32-bit registry keys and system resources.
  • 64-bit PowerShell: This environment is designed for 64-bit systems and can access both 32-bit and 64-bit registry keys and system resources.

Symptoms of Failed Remediation Script

If your remediation script is failing, you might encounter the following symptoms:

  • The script doesn’t execute at all.
  • The script executes partially, but fails to complete.
  • Error messages indicating “script failed” or “unknown error.”

Troubleshooting Steps

Before we dive into the fix, let’s try to identify the root cause of the issue. Follow these troubleshooting steps:

  1. Check the script logs: Review the script logs to identify any error messages or warnings that might indicate the source of the problem.

  2. Verify script syntax: Ensure the script syntax is correct and doesn’t contain any typos or formatting issues.

  3. Test the script manually: Run the script manually on a test device to see if it executes successfully.

The Fix: Modifying the Script to Run in 64-bit PowerShell

Now that we’ve identified the issue, let’s modify the script to run in the 64-bit PowerShell environment. Follow these steps:

Step 1: Update the Script Header

Add the following line at the top of your script:

#requires -RunAs64

This line forces the script to run in the 64-bit PowerShell environment.

Step 2: Update the Script to Use 64-bit Registry Keys

If your script accesses registry keys, update the script to use the 64-bit registry keys instead of the 32-bit keys. For example:

$regKey = "HKLM:\Software\Policies\Microsoft\Windows"

Becomes:

$regKey = "HKLM:\Software\Policies\Microsoft\Windows-wow6432Node"

The “wow6432Node” suffix indicates the 32-bit registry key, which is accessible from the 64-bit PowerShell environment.

Step 3: Update the Script to Use 64-bit System Resources

If your script accesses system resources, such as the Windows Management Instrumentation (WMI) namespace, update the script to use the 64-bit system resources. For example:

$wmi = Get-WmiObject -Class Win32_OperatingSystem

Becomes:

$wmi = Get-WmiObject -Class Win32_OperatingSystem -EnableAllPrivileges

The “-EnableAllPrivileges” parameter enables the script to access the 64-bit WMI namespace.

Common Scenarios and Solutions

Here are some common scenarios where the “Run script 64-bit PowerShell” option might cause issues, along with their solutions:

Scenario Solution
Script fails to access 32-bit registry keys Use the “HKLM:\Software\Policies\Microsoft\Windows-wow6432Node” registry key instead of “HKLM:\Software\Policies\Microsoft\Windows”
Script fails to access 32-bit system resources Use the “-EnableAllPrivileges” parameter with the Get-WmiObject cmdlet to access the 64-bit WMI namespace
Script fails to execute due to 32-bit DLL dependencies Update the script to use 64-bit DLL dependencies or use the “SysWOW64” folder to access 32-bit DLLs

Conclusion

Failed remediation scripts in Intune can be frustrating, but with the right troubleshooting steps and modifications, you can resolve the issue and ensure your scripts execute successfully. Remember to update your script header to force 64-bit PowerShell execution, update registry key references, and adjust system resource access to match the 64-bit environment.

By following these steps and adapting to the 64-bit PowerShell environment, you’ll be able to resolve the “Failed remediation script” issue and ensure your Intune scripts run smoothly.

Happy scripting!

Frequently Asked Question

If you’re having trouble with failed remediation scripts in Intune while running 64-bit PowerShell, you’re in the right place! Here are some questions and answers to get you back on track.

Q1: Why does my remediation script fail to run in Intune even when I’ve selected the “Run script 64-bit PowerShell” option?

This might happen if your script is trying to access 32-bit registry keys or other resources that are not compatible with 64-bit PowerShell. Try rewriting your script to use 64-bit compatible commands and references to resolve this issue.

Q2: How can I troubleshoot the issue when the remediation script fails to run in Intune?

To troubleshoot, check the Intune script troubleshooting logs to identify the error message and the line of code that’s causing the issue. You can also try running the script manually on the target device to see if it runs successfully outside of Intune.

Q3: What are some common causes of failed remediation scripts in Intune?

Common causes of failed remediation scripts in Intune include syntax errors, invalid file paths, and incorrect PowerShell versions. Additionally, scripts may fail due to permissions issues, missing dependencies, or conflicts with other running scripts.

Q4: Can I use a 64-bit PowerShell script to fix issues on a 32-bit device in Intune?

No, you cannot use a 64-bit PowerShell script to fix issues on a 32-bit device in Intune. The script will need to be rewritten to accommodate the 32-bit architecture or use a different scripting language that supports 32-bit devices.

Q5: Are there any best practices to follow when creating remediation scripts in Intune?

Yes, follow best practices such as using a consistent naming convention, commenting your code, and testing your script thoroughly on different devices and platforms before deploying it in Intune.

Leave a Reply

Your email address will not be published. Required fields are marked *