use*_*126 8 windows registry powershell
我需要创建以下注册表项,
HKLM:\software\bmc software\control-m/agent
但由于"代理"之前的正斜杠,我遇到了问题
创建没有正斜杠的条目我没有问题例如:
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-mXXXagent'
Run Code Online (Sandbox Code Playgroud)
但是使用正斜杠创建失败了.
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-m/agent'
Run Code Online (Sandbox Code Playgroud)
New-Item:指定路径上的注册表项不存在.在行:1字符:10 +新项目<<<< -path'HKLM:\ software\bmc software\control-m/agent'+ CategoryInfo:InvalidArgument:(HKEY_LOCAL_MACH ... tware\control-m:String) [New-Item],ArgumentExceptio n + FullyQualifiedErrorId:System.ArgumentException,Microsoft.PowerShell.Commands.NewItemCommand
并且使用PowerShell背景`转义字符也无济于事.
PS C:\powershell> new-item -path 'HKLM:\software\bmc software\control-m`/agent'
Run Code Online (Sandbox Code Playgroud)
New-Item:指定路径上的注册表项不存在.在行:1 char:10 + new-item <<<< -path'HKLM:\ software\bmc software\control-m
/agent' + CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...ware\control-m:String)[New-Item],ArgumentExceptio n + FullyQualifiedErrorId:System.ArgumentException,Microsoft.PowerShell .Commands.NewItemCommand
建议将不胜感激.谢谢
这是对Ansgar指出的帖子的略微修改:
new-item -path 'HKLM:\software\bmc software'
$key = (get-item HKLM:\).OpenSubKey("SOFTWARE\bmc software", $true)
$key.CreateSubKey('control-m/agent')
$key.Close()
Run Code Online (Sandbox Code Playgroud)
这将使用实际/char(0x2F)创建密钥.
小智 -1
下面详细介绍了如何将注册表项(包括正斜杠)串在一起的示例:
$value = "2048"
$value1 = "0"
$regpath = "hklm:\SYSTEM\CurrentControlSet\Services\lanmanworkstation\parameters"
$name = "MaxCmds"
$name1 = "RequireSecuritySignature"
$PropertyType = "Dword"
New-ItemProperty -path $regpath -name $name -value $value -PropertyType $PropertyType
Set-ItemProperty -path $regpath -name $name1 -value $value1
Run Code Online (Sandbox Code Playgroud)
因此,根据您的要求,请执行以下操作:
$name1 = "something with a /"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7382 次 |
| 最近记录: |