Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell要添加注册表项_Powershell_Registry_Regedit - Fatal编程技术网

Powershell要添加注册表项

Powershell要添加注册表项,powershell,registry,regedit,Powershell,Registry,Regedit,我有一个Powershell脚本,可以从基本的Windows操作系统上“构建”一台PC(Windows 7 Pro-明年将转换为10)。我有一些注册表项,在运行这个脚本时添加,它们都工作得很好,没有问题 我必须添加一个新的注册表项来关闭远程桌面服务。我可以在命令行用 reg添加“HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”/v FDENYTSCONNECTS/t reg\U DWORD/d 1/f

我有一个Powershell脚本,可以从基本的Windows操作系统上“构建”一台PC(Windows 7 Pro-明年将转换为10)。我有一些注册表项,在运行这个脚本时添加,它们都工作得很好,没有问题

我必须添加一个新的注册表项来关闭远程桌面服务。我可以在命令行用

reg添加“HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”/v FDENYTSCONNECTS/t reg\U DWORD/d 1/f

它很好用。所以现在我需要通过Powershell脚本添加相同的密钥,但我无法让它工作。我所拥有的是

新项目-路径“HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”-名称fDenyTSConnections-值1 |输出文件$log-追加

当我运行它时,会弹出一些内容

类型:

所以我认为它是在要求一种类型。但如果我添加PropertyType如下

新项目-路径“HKEY\U LOCAL\U MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”-名称fDenyTSConnections-属性类型DWORD-值1 |输出文件$log-追加


它给出了一个错误。我在网上的几个论坛上进行了研究,但似乎没有任何效果。有什么想法吗?

我最终测试并开始工作的是:

cmd/c'reg添加“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”/v fDenyTSConnections/t reg_DWORD/d 1/f'| Out File$log-append


我意识到这是围绕Powershell选项进行的,但这是我现在要做的。不过,我很想知道我在Powershell命令中遗漏了什么。

我最终测试并开始工作的是:

cmd/c'reg添加“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server”/v fDenyTSConnections/t reg_DWORD/d 1/f'| Out File$log-append


我意识到这是围绕Powershell选项进行的,但这是我现在要做的。很想知道我在Powershell命令中遗漏了什么。

您不能同时创建具有属性的注册表项。你需要先做一个,然后再做另一个:

$path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server'

$key = try {
    Get-Item -Path $path -ErrorAction Stop
}
catch {
    New-Item -Path $path -Force
}

New-ItemProperty -Path $key.PSPath -Name fDenyTSConnections -Value 1

不能同时创建具有属性的注册表项。你需要先做一个,然后再做另一个:

$path = 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server'

$key = try {
    Get-Item -Path $path -ErrorAction Stop
}
catch {
    New-Item -Path $path -Force
}

New-ItemProperty -Path $key.PSPath -Name fDenyTSConnections -Value 1

我总是这样创建注册表项/值:

# Set the location to the registry
Set-Location -Path 'HKLM:\Software\Microsoft'

# Create a new Key
Get-Item -Path 'HKLM:\Software\Microsoft' | New-Item -Name 'W10MigInfo\Diskspace Info' -Force

# Create new items with values
New-ItemProperty -Path 'HKLM:\Software\Microsoft\W10MigInfo\Diskspace Info' -Name 'usedDiskspaceCDrive' -Value "$usedDiskspaceCDrive" -PropertyType String -Force
New-ItemProperty -Path 'HKLM:\Software\Microsoft\W10MigInfo\Diskspace Info' -Name 'usedDiskSpaceDDrive' -Value "$usedDiskspaceDDrive" -PropertyType String -Force

# Get out of the Registry
Pop-Location

我总是这样创建注册表项/值:

# Set the location to the registry
Set-Location -Path 'HKLM:\Software\Microsoft'

# Create a new Key
Get-Item -Path 'HKLM:\Software\Microsoft' | New-Item -Name 'W10MigInfo\Diskspace Info' -Force

# Create new items with values
New-ItemProperty -Path 'HKLM:\Software\Microsoft\W10MigInfo\Diskspace Info' -Name 'usedDiskspaceCDrive' -Value "$usedDiskspaceCDrive" -PropertyType String -Force
New-ItemProperty -Path 'HKLM:\Software\Microsoft\W10MigInfo\Diskspace Info' -Name 'usedDiskSpaceDDrive' -Value "$usedDiskspaceDDrive" -PropertyType String -Force

# Get out of the Registry
Pop-Location

我可能错了,但我认为
新项目
没有
-PropertyType
。。。我想这就是
newitemproperty
@techguy1029-那么不断弹出的“Type:”提示符是什么?这可能是
itemptype
意思是Powershell想知道
新项
是否是文件或目录我可能错了,但我认为
新项
没有
-PropertyType
。。。我想这就是
newitemproperty
@techguy1029-那么不断弹出的“Type:”提示符是什么?这可能是
ItemType
,意思是Powershell想知道
newitem
是文件还是目录。最好
测试路径-Path“HKLM:\System\CurrentControlSet\Control\Terminal Server”
首先,并且只有在
测试路径失败时才执行
新项目
——否则,您就“吹走”了所有TS设置。@JeffZeitlin真的吗?在文件系统提供程序中,我注意到它对现有项没有破坏性。我不知道注册表提供程序不是这样。我在注册表中看到了不一致的行为;即使在我“知道”的情况下,它不会影响供应商中的现存项目,但我认为最好的做法是测试和创建,而不是仅仅创建软件。谢谢!这正好有助于解决我的问题。@JeffZeitlin如果目标是覆盖(如果存在密钥),该怎么办?首先删除它是否安全?或者是否有覆盖标志?最好先
测试路径-Path“HKLM:\System\CurrentControlSet\Control\Terminal Server”
,只有
测试路径失败时才执行
新项
,否则,你就“吹走”了所有TS设置。@JeffZeitlin真的吗?在文件系统提供程序中,我注意到它对现有项没有破坏性。我不知道注册表提供程序不是这样。我在注册表中看到了不一致的行为;即使在我“知道”的情况下,它不会影响供应商中的现存项目,但我认为最好的做法是测试和创建,而不是仅仅创建软件。谢谢!这正好有助于解决我的问题。@JeffZeitlin如果目标是覆盖(如果存在密钥),该怎么办?首先删除它是否安全?或者是否有覆盖标志?