PowerShell 脚本用于更改注册表中的 DWORD 值

PowerShell 脚本用于更改注册表中的 DWORD 值

有人可以帮我创建一个可与 Windows 10 Enterprise 一起使用的 PowerShell 脚本,该脚本将DWORD的值更改ConnectionType1,并将下的用户注册表中的DWORD的值更改DeferFlags为。4HKCU:\Network\[drive letter]

以下是我尝试过的但无法正常工作的方法

$registryPath = "HKCU\Network\G"
$Name = "Connection Type"
$value = "0"
IF(!(Test-Path HKCU\Network\G))
  {
      New-Item -Path "HKCU\Network\G" -Force | Out-Null
        New-ItemProperty -Path "HKCU\Network\G" -Name "Connection Type" -Value 1 `
            -PropertyType DWORD -Force | Out-Null}
             ELSE { 

     New-ItemProperty -Path "HKCU\Network\G" -Name "Connection Type" -Value 1 `
        -PropertyType DWORD -Force | Out-Null}

答案1

您几乎已经拥有它了,但是还需要一点点推动,因此下面的 PowerShell 应该可以满足您的需要。

电源外壳

$registryPath = "HKCU:\Network\G";
If ( !(Test-Path $registryPath) ) { New-Item -Path $registryPath -Force; };
New-ItemProperty -Path $registryPath -Name "Connection Type" -Value 1 -PropertyType DWORD -Force;
New-ItemProperty -Path $registryPath -Name "DeferFlags" -Value 4 -PropertyType DWORD -Force;

支持资源

相关内容