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
}
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.
Comments