IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Dealing with registry values


Sujet :

Scripts/Batch

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2018
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2018
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Dealing with registry values
    Bonjour à tous,


    Pour toutes valeurs de registres enfants de "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU" je souhaite remplacer la chaine de caractère "BRZ-SV-FILE-01" par une autre chaîne.
    Mais je me casse les dents sur le type de l'objet retourné (System.Management.Automation.PSCustomObject) qui me limite énormément sur les méthodes de manipulation de chaines et sur le test des propriétés.
    Voici mon code en cours. (J'ai essayé plusieurs versions pour manipuler la chaine de caractère)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    set-location -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer
    # Get-ChildItem -recurse -ErrorAction silentlycontinue | Where-Object {($_.name -match "Map Network Drive") -or ($_.name -match "MountPoints2")} | get-member
    Get-ChildItem -recurse -ErrorAction silentlycontinue | Select-Object -Property pspath,name | foreach {
        if (($_.name -match "Map Network Drive")) {
                    $path = $_.pspath
                    $Object1 = Get-ItemProperty -path $path
                    $object1 | get-member
                    $test=@()
                    $test | Get-Member
                    foreach ($item in $object1) {
                        $test= New-Object psobject -property @{
                               map = ""
                               remotepath =""}
                           
                    }
                     $test.remotepath
        }
        
    }
    Malheureusement la variable $test ne contient aucune valeur dans ses 2 propriétés map et remotepath

    A noter que les variables $Object1 et $Item contiennent ceci :

    PS HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer> $Object1


    PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
    PSChildName : Map Network Drive MRU
    PSProvider : Microsoft.PowerShell.Core\Registry
    a : \\stg-sv-file-04.sanders.fr\Groupes de travail
    MRUList : onmlkjibhgdfeca
    b : \\stg-sv-file-04\groupes de travail
    c : \\brz-sv-file-01\groupes de travail\
    d : \\frrnsspfis-001\sources
    e : \\cybelia.fr\avril\organisation
    f : \\brz-pt-rch-2522\c$
    g : \\brz-sv-file-01\utilisateurs$\emmanuel.gicquel
    h : \\FRPMOPFIS01.act.rad.local\data
    i : \\stg-sv-bckup-3.groupe-glon.fr\e$
    j : \\spr-sv-dc-01\Groupes de travail
    k : \\stg-sv-domno-2\d$
    l : \\FRBKLSPFIS-002\groupes de travail
    m : \\FRASNPFIS01.act.rad.local\SNST
    n : \\frbklspfis-002.cybelia.fr\d$
    o : \\frbklspfis-002.cybelia.fr\Groupes de travail


    A noter également que les membres de ces variables sont :

    PS HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer> $object1 | get-member


    TypeName: System.Management.Automation.PSCustomObject

    Name MemberType Definition
    ---- ---------- ----------
    Equals Method bool Equals(System.Object obj)
    GetHashCode Method int GetHashCode()
    GetType Method type GetType()
    ToString Method string ToString()
    a NoteProperty System.String a=\\stg-sv-file-04.sanders.fr\Groupes de travail
    b NoteProperty System.String b=\\stg-sv-file-04\groupes de travail
    c NoteProperty System.String c=\\brz-sv-file-01\groupes de travail\
    d NoteProperty System.String d=\\frrnsspfis-001\sources
    e NoteProperty System.String e=\\cybelia.fr\avril\organisation
    f NoteProperty System.String f=\\brz-pt-rch-2522\c$
    g NoteProperty System.String g=\\brz-sv-file-01\utilisateurs$\emmanuel.gicquel
    h NoteProperty System.String h=\\FRPMOPFIS01.act.rad.local\data
    i NoteProperty System.String i=\\stg-sv-bckup-3.groupe-glon.fr\e$
    j NoteProperty System.String j=\\spr-sv-dc-01\Groupes de travail
    k NoteProperty System.String k=\\stg-sv-domno-2\d$
    l NoteProperty System.String l=\\FRBKLSPFIS-002\groupes de travail
    m NoteProperty System.String m=\\FRASNPFIS01.act.rad.local\SNST
    MRUList NoteProperty System.String MRUList=onmlkjibhgdfeca
    n NoteProperty System.String n=\\frbklspfis-002.cybelia.fr\d$
    o NoteProperty System.String o=\\frbklspfis-002.cybelia.fr\Groupes de travail
    PSChildName NoteProperty System.String PSChildName=Map Network Drive MRU
    PSParentPath NoteProperty System.String PSParentPath=Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
    PSPath NoteProperty System.String PSPath=Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU
    PSProvider NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.PowerShell.Core\Registry



    A noter aussi que j'ai réussi dans une autre partie du script à modifier d'autres valeurs du registre avec le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    New-PSDrive -PSProvider registry -Root HKEY_USERS -Name HKU
    $Drive = Set-Location -Path HKU:\
    $ListHKU = Get-ChildItem $drive | where {($_.name -match "S-1-5-21") -and ($_.name -notmatch "_classes")} 
    $ListHKU | foreach {
        $HKUNet = $_.pspath+ "\Network\"
        Get-childitem -Path $HKUNet -Recurse -ErrorAction silentlycontinue | Select-Object -property pspath,psiscontainer | Where-Object {$_.psiscontaner -eq $tue} | foreach {
            $path = $_.pspath
            Get-ItemProperty -path $path | Get-Member
            Get-ItemProperty -path $path | Select-Object -Property pschildname,remotepath,ProviderName | foreach {
                    $string = $_.remotepath
                    if (($string.startswith('\\brz-sv-file-01'))) {
                        #$RemotePathLength = $string.length
                        $SubstString = $string.replace("brz-sv-file-01","frbklspfis-002.cybelia.fr")
                        Set-ItemProperty -path $path -name RemotePath -value $SubstString
                        #Write-Host $string `t $RemotePathlength `t $SubstString
                    } elseif ($string.startswith('\\xxx.xxx.xxx.xxx')){
                        $SubstString = $string.replace("xxx.xxx.xxx.xxx","frbklspfis-002.cybelia.fr")
                        Set-ItemProperty -path $path -name RemotePath -value $SubstString
                    }
                } 
            }
    }
    
    Remove-PSDrive -Name HKU


    Avez vous une idée pour me guider dans la manipulation du type de la variable $Object1 ?

    Merci pour votre aide

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    Citation Envoyé par egl35170 Voir le message
    Mais je me casse les dents sur le type de l'objet retourné (System.Management.Automation.PSCustomObject) qui me limite énormément sur les méthodes de manipulation de chaines et sur le test des propriétés.
    Pas certains de comprendre.
    Essaie sans le select-Object qui crée un PSCustomObject à partir de l'objet reçu dans le pipeline.
    Citation Envoyé par egl35170 Voir le message
    Malheureusement la variable $test ne contient aucune valeur dans ses 2 propriétés map et remotepath
    Peut-être faut-il les renseigner, car le premier exemple de code fait ce que tu lui demandes.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Octobre 2018
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux

    Informations forums :
    Inscription : Octobre 2018
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Merci mais
    Bonjour Laurent,

    Merci pour ta réponse mais la cmdlet select-object s'applique à l'arborescence du registre "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU" et le fait que cet objet soit sérialisé ne me pose pas de problème en soit cat je teste juste le path avec succès.
    Ce qui me pose problème c'est la sérialisation de la collection d'objets qu'elle contient retournée par la cmdlet"get-itemproperty". pour obtenir toutes les valeurs contenus dans ce dossiers et pour lesquelles je ne parviens pas à manipuler les chaines de caractères.
    J'ajoute une capture écran "Registry_Tree" pour que le problème soit un peu plus parlant.
    Images attachées Images attachées  

  4. #4
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    est-ce que ceci fonctionne ?
    Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    $key=Get-ItemProperty 'Hkcu:\Software\Microsoft\Windows\CurrentVersion\Explorer\Map Network Drive MRU'
    $key.MRUList
    #a
    $key.MRUList|% {$Key.$_}
    #\\localhost\G$\temp

Discussions similaires

  1. Réponses: 0
    Dernier message: 25/08/2015, 19h48
  2. Message d'erreur: Return-statement with no value
    Par stanfillirenfro dans le forum C++
    Réponses: 4
    Dernier message: 18/01/2014, 20h21
  3. Autocomplete with other values
    Par robinhood2010 dans le forum JSF
    Réponses: 1
    Dernier message: 21/11/2012, 10h18
  4. DXX32: Warn: Registry value too long
    Par korsakoff69 dans le forum DirectX
    Réponses: 1
    Dernier message: 03/06/2012, 00h56
  5. Agent exited on with return value 55
    Par slausseur dans le forum Installation
    Réponses: 1
    Dernier message: 17/10/2007, 16h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo