Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Comparing different Get-ChildItem results

$
0
0

Hi Guys,

Hopefully you can help me. I'm getting close but don't get the result I want.

The idea is that is want to compare several locations (registry/filesystem) before and after.

When I run Get-ChilItem apart, the result is visible, but when I want to automate this in a loop, nothing is visible. Maybe it's really easy for you guys ;-)

This is the code I have now:

[EDIT] I thought i got it...but the results are not what I changed in registry :-S

CLS

#################################################################
#
# Locations
#
#################################################################
[array]$RegistryLocations = @(
    "HKCU:\EUDC","HKCU:\Printers"
)

[array]$FilesystemLocations = @(
    "C:\Program Files","C:\ProgramData"
)

# Count the amount registry locations
$AmountOfRegistryLocations = $RegistryLocations.Count
# Count the amount registry locations
$AmountOfFilesystemLocations = $FilesystemLocations.Count

#################################################################
#
# >>>>>> Snapshot Before
#
#################################################################
Write-Host "Scan $AmountOfRegistryLocation locations before... "

$before = @().Clear()
$i = 0
foreach($location in $RegistryLocations)
{    
    $i++
    Write-Progress -activity "Scanning Registry..." -status "Scanning $location ($i of $($AmountOfRegistryLocations))" -percentComplete (($i / $AmountOfRegistryLocations)  * 100)
    $before += Get-ChildItem -Path $location -Recurse -ErrorAction SilentlyContinue | select Name
}

#################################################################
#
# >>>>>> Snapshot After
#
#################################################################
Write-Host "Scan $AmountOfRegistryLocation locations after... "

$after = @().Clear()
$i = 0
foreach($location in $RegistryLocations)
{
    $i++ 
    Write-Progress -activity "Scanning Registry..." -status "Scanning $location ($i of $($AmountOfRegistryLocations))" -percentComplete (($i / $AmountOfRegistryLocations)  * 100)  
    $after += Get-ChildItem -Path $location -Recurse -ErrorAction SilentlyContinue | select Name
}

#################################################################
#
# Comparison
#
#################################################################

Compare-Object $before $after | %{ $_.InputObject}

Write-Host "Comparison completed!"




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>