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