im trying to extract the active users of my pc via registry keys,i check HKLM... and HKU... and then i compare them to check for the active users, but when i try to extract the data via out-file -force to remove the previous users saved on the txt`s and i execute the script again, it only gives me one result as if only one user is active.
$regLM = "Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\"
$clav1 = Get-Item "$regLM\S-1-X-Y-*"
# Salida de usus de HKLM
foreach ($usus1 in $clav1.PSChildName) {
Write-Host "Clave de usu HKLM: $usus1"
$usus1 | Out-File "C:\InH\InstM\PRUREG1.txt" -Force
#$usus1 >> "C:\InH\InstM\PRUREG1.txt"
}
Write-Host "Claves de USU de HKLM ^"
$regCU = "Registry::HKEY_USERS\"
$clav2 = Get-Item "$regCU\S-1-X-Y-*"
# Salida de usus de HKUSU
foreach ($usus2 in $clav2.PSChildName) {
Write-Host "Clave de usu HKU: $usus2"
$usus2 | Out-File "C:\InH\InstM\PRUREG2.txt" -Force
#$usus2 >> "C:\InH\InstM\PRUREG2.txt"
}
Write-Host "Claves de USU de HKUSU ^"
$clavesiguales = @{
ReferenceObject = (Get-Content -Path "C:\InH\InstM\PRUREG1.txt")
DifferenceObject = (Get-Content -Path "C:\InH\InstM\PRUREG2.txt")
}
$clavlimpias = Compare-Object @clavesiguales -ExcludeDifferent | Select-Object -ExpandProperty InputObject
Write-Host "Se sacaron las claves y se guardan en un txt $clavlimpias"
$clavlimpias | Out-File "C:\InH\InstM\USUACTIV.txt" -Force
Heres the exit of the code, doesnt get me the keys of the users.

The commented lines are how it should work but it doesnt delete the data stored on itself everytime it gets executed.
