读取和比较注册表项的脚本

Script to read and compare registry entries

我是 PowerShell 的新手,我被这个问题卡住了。

到目前为止我已经想到了这个...但我认为这不是解决问题的正确方法。我知道我可能需要使用 compare-object cmdlet,但不确定如何应用它。

$path1 ="HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$path2 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run
$destination = "(FileName.txt)"
$results = Get-ItemProperty $path1 $path2

如有任何帮助,我们将不胜感激,因为我的教授无法为我提供有关实际脚本的任何类型的帮助。

比较你是否导出了reg文件,你可以这样做:

$location1 = "C:\temp\location1";
$location2 = "C:\temp\location2";
$location3 = "C:\temp";

Compare-Object $(Get-Content "$location1\file1.reg") $(Get-Content "$location2\file2.reg") | 
    Where-Object { IsNotAccepted($_.InputObject) } | 
    Out-File "$location3\NotAcceptedEntries.txt" -Force

function IsNotAccepted($entry){
    $accepted = $false;
    # $name = $entry.Split('=')[0]
    # $value = $entry.Split('=')[1]

    # Put your logics here

    return -Not($accepted);
}

注意$_.InputObject代表条目,例如

"C:\Program Files (x86)-Zipz.exe.FriendlyAppName"="7-Zip Console 2"

你也可以通过检查$_.SideIndicator知道那个文件在哪个文件中。如果它 returns => 就意味着正确的文件 (file2.reg) 有那个区别。相反 <= 表示在左侧文件中发现差异 (file1.reg)。