PowerShell/Registre
Aller à la navigation
Aller à la recherche
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
#}
Ajustement des effets pour la performance pour l'utilisateur courant
# Déclaration de la fonction "SetVisualFXPerformance"
Function SetVisualFXPerformance {
Write-Output "Ajustement des effets pour la performance..."
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "DragFullWindows" -Type String -Value 0
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "FontSmoothing" -Type String -Value 1
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "MenuShowDelay" -Type String -Value 0
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "UserPreferencesMask" -Type Binary -Value ([byte[]](90,32,07,80,10,0,0,0))
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name "MinAnimate" -Type String -Value 0
Set-ItemProperty -Path "HKCU:\Control Panel\Keyboard" -Name "KeyboardDelay" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "IconsOnly" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ListviewAlphaSelect" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "ListviewShadow" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarAnimations" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "TaskbarGlomLevel" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "MMTaskbarGlomLevel" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name "IconSizePreference" -Type DWord -Value 2
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects" -Name "VisualFXSetting" -Type DWord -Value 3
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name "EnableTransparency" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\DWM" -Name "EnableAeroPeek" -Type DWord -Value 0
}
# Exécution de la fonction
SetVisualFXPerformance
Fichier d'inscription au registre (.reg)
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Edge] ; Autoriser le contenu Microsoft sur la page du nouvel onglet ; https://learn.microsoft.com/fr-fr/deployedge/microsoft-edge-browser-policies/newtabpagecontentenabled "NewTabPageContentEnabled"=dword:00000000 "NewTabPageAllowedBackgroundTypes"=dword:00000003 "NewTabPageQuickLinksEnabled"=dword:00000000 "AlwaysOpenPdfExternally"==dword:00000001 ; page d accueil par défaut ; Définir la page Nouvel onglet comme page d accueil ; https://learn.microsoft.com/fr-fr/deployedge/microsoft-edge-browser-policies/homepageisnewtabpage "HomepageIsNewTabPage"=dword:00000001 ; https://learn.microsoft.com/fr-fr/deployedge/microsoft-edge-browser-policies/homepagelocation "HomepageLocation"="https://www.google.fr" ; Configurer l URL du nouvel onglet ; https://learn.microsoft.com/fr-fr/deployedge/microsoft-edge-browser-policies/newtabpagelocation "NewTabPageLocation"="https://www.google.fr" [HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Edge\Recommended] "AlwaysOpenPdfExternally"==dword:00000001 "ShowHomeButton"=dword:00000001 "HomepageIsNewTabPage"=dword:00000001 "HomepageLocation"="https://www.google.fr" "NewTabPageLocation"="https://www.google.fr" [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge] "NewTabPageContentEnabled"=dword:00000000 "NewTabPageAllowedBackgroundTypes"=dword:00000003 "NewTabPageQuickLinksEnabled"=dword:00000000 "NewTabPageContentEnabled"=dword:00000000 "HomepageIsNewTabPage"=dword:00000001 "HomepageLocation"="https://www.google.fr" "NewTabPageLocation"="https://www.google.fr" [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge\Recommended] "HomepageIsNewTabPage"=dword:00000001 "HomepageLocation"="https://www.google.fr" "NewTabPageLocation"="https://www.google.fr"
Script PowerShell
# Déclaration de la fonction "SetWebBrowerHomePage"
Function SetWebBrowerHomePage {
$sitWeb = "https://www.google.fr"
$sitWeb = "https://kono.phpage.fr"
Write-Host "Ajustement pour le navigateur Microsoft Edge, en cours..." -ForegroundColor Yellow
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "NewTabPageContentEnabled" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "NewTabPageAllowedBackgroundTypes" -Type DWord -Value 3
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "NewTabPageQuickLinksEnabled" -Type DWord -Value 0
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "AlwaysOpenPdfExternally" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "HomepageIsNewTabPage" -Type DWord -Value 1
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "HomepageLocation" -Type string -Value $sitWeb
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "NewTabPageLocation" -Type String -Value $sitWeb
Set-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "AlwaysOpenPdfExternally" -Type DWord -Value 1
Write-Host "Ajustement pour le navigateur Microsoft Edge, terminé" -ForegroundColor Green
Write-Host "Contrôle de la clé 'HomepageLocation' :" (Get-ItemProperty -Path "HKCU:\SOFTWARE\Policies\Microsoft\Edge" -Name "HomepageLocation").HomepageLocation
}
# Exécution de la fonction
SetWebBrowerHomePage