« PowerShell/Registre » : différence entre les versions
Aller à la navigation
Aller à la recherche
| Ligne 33 : | Ligne 33 : | ||
== Création de plusieurs clés == | == Création de plusieurs clés == | ||
=== Exemple 1 === | |||
<source> | <source> | ||
$racine = "S-1-5-21-1234567890-123456789-123456789-" | $racine = "S-1-5-21-1234567890-123456789-123456789-" | ||
| Ligne 48 : | Ligne 50 : | ||
} | } | ||
</source> | </source> | ||
=== Exemple 2 === | |||
<source> | |||
#HKEY_USERS\S-1-5-21-1234567890-1234567890-123456789-1234 C:\Users\dm C:\Users\local_dm | |||
#HKEY_USERS\S-1-5-21-1234567890-1234567890-123456789-1248 C:\Users\adminphp C:\Users\local_adminphp | |||
$racine = "S-1-5-21-1234567890-1234567890-123456789" | |||
$liste = Get-ChildItem -Path Registry::HKEY_USERS\ | Where-Object {$_.Name -match "$racine-\d{4}$"} | |||
$compte = "$racine-1248" | |||
#foreach ($compte in $liste) { | |||
$branche = "Registry::HKEY_USERS\$compte" | |||
## Affichage de la valeur de la clé "USERNAME" | |||
(Get-ItemProperty -Path $branche -Name USERNAME).username | |||
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name UserPreferencesMask | |||
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name DragFullWindows | |||
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name FontSmoothing | |||
Get-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name EnableTransparency | |||
## test de présence de la clé ; si non présence alors création | |||
$valeurs = Get-ItemProperty -path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" | |||
if ($valeurs.PSObject.Properties.Name -notcontains "TaskbarGlomLevel") { | |||
New-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarGlomLevel" -PropertyType DWord -Value "1" | |||
} | |||
#Get-ItemProperty -Path "$branche\Control Panel\Desktop\WindowMetrics" -Name MinAnimate | |||
## Création d'éléments | |||
#New-ItemProperty -Path $branche -Name "test" -PropertyType String -Value "Alphorm" | |||
#New-ItemProperty -Path $branche -Name "HomepageLocation" -PropertyType String -Value "http://phpage.fr" | |||
## Modification de valeur d'élément | |||
Set-ItemProperty -Path "$branche\Control Panel\Desktop" -Name DragFullWindows -Value "0" | |||
Set-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name EnableTransparency -Value "0" | |||
#Set-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name TaskbarGlomLevel -value | |||
#}</source> | |||
== Voir aussi == | == Voir aussi == | ||
Version du 31 octobre 2025 à 16:59
PowerShell et le registre.
Généralité
Les différentes entrées pour la base de registre (BDR) sont :
| Racine | Abrégé | Commentaire |
|---|---|---|
HKEY_CLASSES_ROOT |
HKCR |
|
HKEY_CURRENT_USER |
HKCU |
|
HKEY_LOCAL_MACHINE |
HKLM |
|
HKEY_USERS |
HKU |
|
HKEY_CURRENT_CONFIG |
Liste d'éléments concernant les utilisateurs sur un serveur RDS
$utilisateurListe = Get-ChildItem -Path Registry::HKEY_USERS\ | Where-Object {$_.Name -match '^HKEY_USERS\\S-1-5-21-[\d\-]+$'}
foreach ($utilisateur in $utilisateurListe) {
$chemin = Join-Path $utilisateur.PSPath "Software\FSLogix\Profiles\Session"
$element = Get-ItemProperty -Path $chemin
Write-Host $utilisateur, $element.ProfilePath, $element.LocalProfilePath
}
Création de plusieurs clés
Exemple 1
$racine = "S-1-5-21-1234567890-123456789-123456789-"
$liste = Get-ChildItem -Path Registry::HKEY_USERS\ | Where-Object {$_.Name -match "$racine\d{4}$"}
foreach ($compte in $liste) {
$branche = "Registry::\$compte\Volatile Environment\"
## Affichage de la valeur de la clé "USERNAME"
(Get-ItemProperty -Path $branche -Name USERNAME).username
## Création d'éléments
New-ItemProperty -Path $branche -Name "test" -PropertyType String -Value "Alphorm"
New-ItemProperty -Path $branche -Name "HomepageLocation" -PropertyType String -Value "http://phpage.fr"
}
Exemple 2
#HKEY_USERS\S-1-5-21-1234567890-1234567890-123456789-1234 C:\Users\dm C:\Users\local_dm
#HKEY_USERS\S-1-5-21-1234567890-1234567890-123456789-1248 C:\Users\adminphp C:\Users\local_adminphp
$racine = "S-1-5-21-1234567890-1234567890-123456789"
$liste = Get-ChildItem -Path Registry::HKEY_USERS\ | Where-Object {$_.Name -match "$racine-\d{4}$"}
$compte = "$racine-1248"
#foreach ($compte in $liste) {
$branche = "Registry::HKEY_USERS\$compte"
## Affichage de la valeur de la clé "USERNAME"
(Get-ItemProperty -Path $branche -Name USERNAME).username
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name UserPreferencesMask
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name DragFullWindows
Get-ItemProperty -Path "$branche\Control Panel\Desktop" -Name FontSmoothing
Get-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name EnableTransparency
## test de présence de la clé ; si non présence alors création
$valeurs = Get-ItemProperty -path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
if ($valeurs.PSObject.Properties.Name -notcontains "TaskbarGlomLevel") {
New-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarGlomLevel" -PropertyType DWord -Value "1"
}
#Get-ItemProperty -Path "$branche\Control Panel\Desktop\WindowMetrics" -Name MinAnimate
## Création d'éléments
#New-ItemProperty -Path $branche -Name "test" -PropertyType String -Value "Alphorm"
#New-ItemProperty -Path $branche -Name "HomepageLocation" -PropertyType String -Value "http://phpage.fr"
## Modification de valeur d'élément
Set-ItemProperty -Path "$branche\Control Panel\Desktop" -Name DragFullWindows -Value "0"
Set-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name EnableTransparency -Value "0"
#Set-ItemProperty -Path "$branche\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name TaskbarGlomLevel -value
#}