Intune Proactive Remediation: Powershell-Skript not finding Registry-Path

Simon Aebi 21 Reputation points
2021-02-12T13:08:59.337+00:00

First: I'm not that good at powershell, but some easy scripts are ok. Right now i'm facing a problem and i just can't find the solution.

Within Intune i try to implement a detection script that detects a value within the registry if its 1. Here's the script i did:

$value = Get-ItemPropertyValue -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost' -Name "4G"

try{
if ($value -eq 1)
{
write-host "Compliant:True"
exit 0
}
write-host "Compliant:False - run remediation"
exit 1

}
catch{
write-host "Comliant:False - run remediation"
exit 1
}

If i start this script manually with powershell (admin), the script works just fine. But if i deploy the script trough intune proactive remediation, it always tells me that theres no specific registry path - but its there fore sure. I first thought i may be the conext in whicht powershell via intune runs - but what else than system or admin should it be...

I see it comming - the solution will be absolutly clear and easy once someone will give the answer :D

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,580 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
5,326 questions
0 comments No comments
{count} votes

Accepted answer
  1. Crystal-MSFT 50,591 Reputation points Microsoft Vendor
    2021-02-15T02:34:02.29+00:00

    @Simon Aebi Based on my research, if we run script in a 64-bit Powershell host on a 64-bit client architecture, we can set "Run script in 64-bit PowerShell host" as Yes:
    https://learn.microsoft.com/en-us/mem/intune/apps/intune-management-extension#create-a-script-policy-and-assign-it

    Meanwhile, find an article mentioned to write registry keys in x64 hive and not WOW6432Node. We can read it for the reference.
    https://oliverkieselbach.com/2017/11/29/deep-dive-microsoft-intune-management-extension-powershell-scripts/
    Note: Non-Microsoft link, just for the reference.

    Hope it can help.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. MotoX80 34,761 Reputation points
    2021-02-13T03:26:12.027+00:00

    Intune is probably running in 32 bit. mode.

    https://blog.italik.co.uk/running-powershell-scripts-using-intune/

    1 person found this answer helpful.
    0 comments No comments

  2. Simon Aebi 21 Reputation points
    2021-02-18T08:02:47.323+00:00

    Thanks guys

    That was the case - 64/32bit! Thanks a lot and stay safe :)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.