Powershell a registry key via InTune

Rob 'Emrys' Brown

I've written a script to check for the presence of a key in Win10 registry and write the key if it's not found.

The script does actually work, however InTune dashboard is reporting that it fails.

Would appreciate some insight/thoughts.

$registryPath = "HKLM:\SOFTWARE\Policies\Google\Chrome"
$Name = "CloudManagementEnrollmentToken"
$value = ##REDACTED

Set-ExecutionPolicy -executionpolicy Undefined -Scope LocalMachine

IF(!(Test-Path $registryPath))
{
new-item -path $registryPath -force | out-null
    new-itemproperty -Path $registryPath -name $name -value $value
    -propertytype string -force | out-null
}
else {
exit
}

enter image description here

Theo

You need to set your registry path using either the predefined HKLM: drive

$registryPath = 'HKLM:\SOFTWARE\Policies\Google\Chrome'

or use the long registry syntax

$registryPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome'

so PowerShell will know you are trying to do stuff inside the registry and not of the file system.

See also Working with Registry Keys

Also, -propertytype string -force | out-null should be in the same line as the New-ItemProperty cmdlet, because otherwise PowerShell will try and see that as a new command (which doesn't exist)

New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType string -Force | Out-Null

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Deploying Registry Keys Script via Intune

Set printer security binary key in registry via PowerShell

How to deploy a powershell-installer via the intune-portal?

Add registry key via batchfile

Powershell - Create Volatile Registry key?

Powershell to find registry key and delete it

How do I add a variable into a specific registry key path via Powershell?

Installshield - checking for key in registry failed with powershell

Return key path from Registry Using Powershell

Powershell - manage error when registry key not exist

Unable to get pnputil.exe to function in PowerShell script pushed via MS Intune

ex/importing multivalue registry keys in PowerShell via XML

Renaming volume created via "DOS Devices" registry key?

How to get Data from a registry key value via command line

Linking to DLL via registry key ignored during debugging in Visual Studio

PowerShell script to ask registry for exists key and true/false output

Bug in Wix? Is ps:SnapIn writing to the wrong registry key with PowerShell 3.0?

how to get the data value of the registry value inside a key using powershell

using REG ADD in PowerShell to add registry key with double quotes

Powershell - How to search for hashed registry key with known subkey name and value

How can I get and change the Value of the "(Standard)" key in the Registry with Powershell

Run Powershell script in the background through Intune

Installation error when trying to deploy TeamViewer host via Intune

"The parameter is incorrect" error when trying to get a registry key using Windows API via windows crate

Unable to delete registry key in HKLM\Microsoft\Windows\CurrentVersion\Run via commandline

Fast Registry Searcher in Powershell

Editing CurrentControlSet in the registry with powershell

Detection Method - powershell - registry

Counting registry entries in powershell

TOP Ranking

HotTag

Archive