0
votes

I am very new to PowerShell and I am getting stuck on this question.

  • Read the registry entries from both of the locations named in the project description.
    HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Run HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/Run
  • Compare each entry to a list of acceptable entries. The acceptable entry list is from a text file named "Acceptable_Reg.txt" that will accompany the script when the script is downloaded.
  • Produce a text file report that lists all unacceptable registry entries. Save the report using the computer name as the file name.
  • Transmit the report file to the following intranet address: intranet.xyzcompany.com/bad_reg.aspx

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.

1
What are "both of the locations named in the project description"? What is the format of Acceptable_Reg.txt? What results does your code produce? I can see that your first line should be $path ="HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" (note the colon and backslashes). - Lance U. Matthews
If I could get help on the compare task that would be most helpful. I am just lost. I have seen things like PS C:\> $file1 PS C:\> $file2 compare-object $file1 $file2 but was unsure if this would work for registry entries? - NewCoder04
@NewCoder04, yes that should work to get the differences as long you have exported both reg files. e.g Compare-Object $(Get-Content "$location1\file1.reg") $(Get-Content "$location2\file2.reg") | Out-File "c:\temp\differences.txt" - derloopkat

1 Answers

0
votes

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).