Home > Back-end >  Powershell a registry key via InTune
Powershell a registry key via InTune

Time:01-05

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

CodePudding user response:

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
  •  Tags:  
  • Related