1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
if (Test-Path "HKU:\S-1-5-21-1606980848-484061587-682003330-1613123") {
Write-Host "Found"
}
# Chemin de départ dans la base de registre
$startingRegistryPath = "HKU:\"
# Nouvelle valeur à créer ou à modifier
$newValueName = "IsPromoted"
$newValueData = 1
# Fonction récursive pour la recherche, navigation et modification de la valeur
function SearchNavigateAndModifyValue($currentPath) {
$currentKey = Get-Item -Path $currentPath -ErrorAction SilentlyContinue
if ($currentKey -ne $null) {
$values = Get-ItemProperty -Path $currentKey.PSPath
if ($values.InitialTooltip -eq "Assistance") {
Set-Location -Path $currentKey.PSPath
Write-Host "Navigated to key with matching value: $($currentKey.Name)"
if (-not $values.PSObject.Properties.Name.Contains($newValueName)) {
New-ItemProperty -Path $currentKey.PSPath -Name $newValueName -Value $newValueData -PropertyType DWORD
Write-Host "New value created: $newValueName = $newValueData"
} else {
Set-ItemProperty -Path $currentKey.PSPath -Name $newValueName -Value $newValueData
Write-Host "Value modified: $newValueName = $newValueData"
}
return $true # Indiquer que la modification a été effectuée et sortir de la fonction
}
$subKeys = Get-ChildItem -Path $currentKey.PSPath
foreach ($subKey in $subKeys) {
if (SearchNavigateAndModifyValue $subKey.PSPath) {
return $true # Si la modification a été effectuée, sortir de la fonction
}
}
}
return $false # Aucune modification n'a été effectuée
}
# Appeler la fonction avec le chemin de départ
SearchNavigateAndModifyValue $startingRegistryPath |
Partager