Question Ajout de valeur dans un clé de registre

Plus d'informations
il y a 9 ans 3 mois #22760 par Mimid
Bonjour à tous,

Je recherche à créer un script qui va insérer des valeurs dans une clé de registre.

Pour cela, je lis un fichier CSV, et pour chaque ligne de ce fichier CSV je génère un ligne. J'intègre cette ligne dans un fichier texte.

Toutes les lignes de ce fichier texte doivent etre intégré à la suite (c'est à dire sans retour chariot) dans la clé de registre.

Je bloque car je ne sais pas comment traiter l'importation des lignes de mon fichier texte en supprimant le retour chariot.

Je m'y prend peut être mal.

Pouvez-vous m'aider ?

Merci

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 3 mois #22767 par Laurent Dardenne
Si tu transformes ton tableau de ligne en chaîne, tu peux le manipuler plus facilement :
[code:1]
@'
Denis
voiture
4
Michel
Velo
2
Marc
Train
3
'@ > c:\temp\datas.txt
$T=GC c:\temp\datas.txt

\"$T\".replace(\"`n\",\"\"«»)
[byte[]][char[]]\"$T\"
[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 3 mois #22820 par crogiez
[code:1]
# philippe crogiez

function ecrit_log($llogf){
#rem create log
$llog=get-date -Format \"yyyy-MM-dd-HH-mm-ss\"
$llog=$llog+\";\"+$llogf
$llog
$llog >> $malog
}

#recuperation du dossier courant
$monchemin=$MyInvocation.InvocationName
$monchemin
$mondossier=(split-path -Path $monchemin -Parent) + \"\\"
$mondossier
$monscript=split-path -path $monchemin -leaf
$monscript
$malog=$mondossier+$monscript.Substring(0,$monscript.IndexOf(\".\"«»))+\".log\"
$malog
$moncsv=$mondossier+$monscript.Substring(0,$monscript.IndexOf(\".\"«»))+\".csv\"
$moncsv
$crlf=[char]13+[char]10

#rem create log
remove-item -Path $malog -ErrorAction SilentlyContinue
$mlog=\"\";1..$monchemin.Length | % {$mlog=$mlog+\"-\"};ecrit_log($mlog)
$mlog=$monchemin; ecrit_log($mlog)

#Je recherche à créer un script qui va insérer des valeurs dans une clé de registre.
#Pour cela, je lis un fichier CSV,

@'
L1V1;L1V2;L1V3
L2V1;L2V2;L2V3
L3V1;L3V2;L3V3
L4V1;L4V2;L4V3
'@ > $moncsv
$contenu=Get-Content $moncsv
\"contenu\"
$contenu

#et pour chaque ligne de ce fichier CSV je génère un ligne.
#J'intègre cette ligne dans un fichier texte.
#Toutes les lignes de ce fichier texte doivent etre intégré à la suite
#(c'est à dire sans retour chariot) dans la clé de registre.

$ligne=\"\"
$contenu|%{
$ligne=$ligne+$_
}
$ligne

Get-PSDrive

#chemin bidon qui sert à rien
$cheminreg = \"HKCU:\Control Panel\Keyboard\"
$clef = \"maclef\"
$value = $ligne

New-ItemProperty -Path $cheminreg -Name $clef -Value $value

#rem fin log
$mlog=\"end\"; ecrit_log($mlog)

[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 3 mois #22821 par crogiez
[code:1]
#chemin bidon qui sert à rien
$cheminreg = \"HKCU:\Control Panel\Keyboard\"
$clef = \"maclef\"
$value = $ligne

New-ItemProperty -Path $cheminreg -Name $clef -Value $value -Force

#rem fin log
$mlog=\"end\"; ecrit_log($mlog)

[/code:1]

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 3 mois #22822 par crogiez
x<br><br>Message édité par: crogiez, à: 15/12/16 14:55
Pièces jointes :

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 3 mois #22823 par crogiez
2016-12-15-14-53-16;
2016-12-15-14-53-16;C:\Users\admb26829as\Documents\PS_DEV\regtxt\regtxt.ps1
contenu
L1V1;L1V2;L1V3
L2V1;L2V2;L2V3
L3V1;L3V2;L3V3
L4V1;L4V2;L4V3
L1V1;L1V2;L1V3L2V1;L2V2;L2V3L3V1;L3V2;L3V3L4V1;L4V2;L4V3


maclef : L1V1;L1V2;L1V3L2V1;L2V2;L2V3L3V1;L3V2;L3V3L4V1;L4V2;L4V3
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Control Panel\Keyboard
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Control Panel
PSChildName : Keyboard
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry

2016-12-15-14-53-16;end

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.048 secondes
Propulsé par Kunena