I have a PowerShell script which should compare two .reg files (reg export files). I want to provide a registry key name and compare the value of this key in those files. My problem is with the regex to only choose the value of the specific key...
The Problem is that the output is not only the value of the key I provide but also all the following lines in the regfile... (that's where I fail with the RegEx)
content of the regfile (example to test):
"DWORD"=dword:fefefeff
"String"="agnhqorewthosdgfalsfalsbvoweirnfapjfpaqwogfjasgj"
"DWORD2"=dword:fefefefe
"qword"=hex(b):fa,ad,df,fa,ad,df,fa,ad
PowerShell Code:
$RegKeyName = "DWORD2"
$regex = ('"{0}"=(.*(?:(?!\n"[^\n"]+"=)\n.*)*)' -f [RegEx]::Escape($RegKeyName))
[regex]::Matches($regfilecontent ,$regex) | foreach { $_.groups[1].value }
expected result for example $RegKeyName=DWORD2 should be: dword:fefefefe
actual result is: dword:fefefefe "qword"=hex(b):fa,ad,df,fa,ad,df,fa,ad
好的,这很简单,我只需要先将内容转换为适当的字符串,然后结果如预期的那样:
$regfilecontent = $regfilecontent |Out-String
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.