I am very new to PowerShell and I am getting stuck on this question.
I have come up with this so far...but I don't think this is the right way to go about it. I know I will probably need to use the compare-object cmdlet but am unsure how to apply it.
$path1 ="HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$path2 = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run
$destination = "(FileName.txt)"
$results = Get-ItemProperty $path1 $path2
Any help on this would be greatly appreciated because my professor is unable to provide me any type of help with the actual script.
For comparing if you have exported the reg files, you can do:
$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);
}
Note that $_.InputObject
represents the entry, e.g.
"C:\Program Files (x86)\7-Zip\7z.exe.FriendlyAppName"="7-Zip Console 2"
You also can know in which file was that by checking $_.SideIndicator
. If it returns =>
it means right file (file2.reg) has that difference. Conversely <=
means the difference was found in left file (file1.reg).