通过 InTune Powershell 注册表项
Powershell a registry key via InTune
我编写了一个脚本来检查 Win10 注册表中是否存在密钥,如果找不到则写入该密钥。
该脚本确实有效,但 InTune 仪表板报告它失败。
将不胜感激 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
}
您需要使用预定义的 HKLM:
驱动器
设置注册表路径
$registryPath = 'HKLM:\SOFTWARE\Policies\Google\Chrome'
或使用长注册表语法
$registryPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome'
这样 PowerShell 就会知道您正在尝试在注册表中而不是在文件系统中执行操作。
此外,-propertytype string -force | out-null
应该与 New-ItemProperty
cmdlet 在同一行,否则 PowerShell 将尝试将其视为新命令(不存在)
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType string -Force | Out-Null
我编写了一个脚本来检查 Win10 注册表中是否存在密钥,如果找不到则写入该密钥。
该脚本确实有效,但 InTune 仪表板报告它失败。
将不胜感激 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
}
您需要使用预定义的 HKLM:
驱动器
$registryPath = 'HKLM:\SOFTWARE\Policies\Google\Chrome'
或使用长注册表语法
$registryPath = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome'
这样 PowerShell 就会知道您正在尝试在注册表中而不是在文件系统中执行操作。
此外,-propertytype string -force | out-null
应该与 New-ItemProperty
cmdlet 在同一行,否则 PowerShell 将尝试将其视为新命令(不存在)
New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType string -Force | Out-Null