简体   繁体   中英

Powershell a registry key via InTune

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 -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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM