Question Recherche et remplacement

Plus d'informations
il y a 5 ans 4 jours #28794 par Agrougroum00
Réponse de Agrougroum00 sur le sujet Re:Recherche et remplacement
En fait, oui je parle d'un fichier retouché, car je manipule les données afin d'insérer les commandes powershell dedans.

A l'origine, en début de script, mon fichier brut, est généré par la commande:
[code:1]Get-WmiObject -Class Win32_Share -ComputerName ($Server +\".domain.com\"«») | Select-Object Path, Name[/code:1]

Cette commande passée au début de mon script, me génère un fichier, dont le contenu est le suivant :
[code:1]
Path Name
---- ----
C:\windows ADMIN$
D:\PARTAGES\GET\AGENCE-BATIMENT-GET-CO AGENCE-BATIMENT-GET-CO
C:\ C$
D:\PARTAGES\GET\cablage-maintenance cablage-maintenance
D:\PARTAGES\GET\CENTRE-GRANDS-PROJETS CENTRE-GRANDS-PROJETS
D:\PARTAGES\Centre_multi_metier Centre_multi_metier
D:\PARTAGES\Centre_Nord Centre_Nord
D:\PARTAGES\commun commun
D:\PARTAGES\controle gestion 44 controle gestion 44
D:\ D$

[/code:1]

Je pars de ce fichier pour le retravailler et faire des manipulations de chaines de caractères pour obtenir mon fichier \"retouchée avec mes commandes Powershell.

Concrêtement, travailler sur le fichier d'origine ne me gêne pas, bien au contraire, et ce sera surement plus simple a traiter :)
Si je peux arriver la même chose à la fin, ça me va :)

Le truc, c'est que je ne vois aps comment faire, même avec les commandes que tu m'as envoyé, pour insérer le contenu du champ \"Name\" dans le champ \"Path\" en remplacement de ce qu'il y a après le backslash (-leaf)

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

Plus d'informations
il y a 5 ans 4 jours #28796 par Laurent Dardenne
A partir de ton exemple (path,name) donne moi 2-3 exemples de ce que tu veux avoir comme résultat (avant Et après) afin de les utiliser avec la commande New-DfsnFolder.

Tutoriels PowerShell

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

Plus d'informations
il y a 5 ans 4 jours #28797 par Agrougroum00
Réponse de Agrougroum00 sur le sujet Re:Recherche et remplacement
Ci dessous :

[code:1]Extract avec la commande Get-WmiObject -Class Win32_Share -ComputerName ($Server +\".domain.com\"«») | Select-Object Path, Name

Path Name
---- ----

D:\PARTAGES\GET\cablage-maintenance cablage
D:\PARTAGES\GET\CENTRE-GRANDS-PROJETS CENTRE-GRANDS-PROJETS
D:\PARTAGES\commun commun_centre
D:\PARTAGES\controle gestion 44 controle_gestion_44

[/code:1]

Ci dessous : Ce que je souhaite

[code:1]

Path Name
---- ----

D:\PARTAGES\GET\cablage cablage
D:\PARTAGES\GET\CENTRE-GRANDS-PROJETS CENTRE-GRANDS-PROJETS
D:\PARTAGES\commun_centre commun_centre
D:\PARTAGES\controle_gestion_44 controle_gestion_44

[/code:1]

Pour expliquer : il arrive que certains Partages portent un nom différent (Name) du dossier vers lequel ils pointent (Path)

Ce que je souhaite:
[code:1]
C'est remplacer :

Path Name
---- ----
D:\PARTAGES\GET\$PathName $ShareName
D:\PARTAGES\GET\$PathName $ShareName
D:\PARTAGES\GET\$PathName $ShareName
D:\PARTAGES\$PathName $ShareName
D:\PARTAGES\$PathName $ShareName

Par:

Path Name
---- ----
D:\PARTAGES\GET\$ShareName $ShareName
D:\PARTAGES\GET\$ShareName $ShareName
D:\PARTAGES\GET\$ShareName $ShareName
D:\PARTAGES\$ShareName $ShareName
D:\PARTAGES\$ShareName $ShareName

[/code:1]

Voila :)

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

Plus d'informations
il y a 5 ans 4 jours #28800 par Laurent Dardenne
Avec un jeu de test simulant le résultat obtenu avec WMI :
[code:1]
Function New-PathShare{
param(
[Parameter(Mandatory=$True,position=0)]
$Path,
[Parameter(Mandatory=$True,position=1)]
$Name
)
[pscustomobject]@{
PSTypeName='PathShare';
Path=$Path;
Name=$Name;
}
}# New-PathShare

$DatasFromWMI=@(
New-PathShare -Path 'D:\PARTAGES\GET\cablage' -Name 'cablage'
New-PathShare -Path 'D:\PARTAGES\GET\CENTRE-GRANDS-PROJETS' -Name 'CENTRE-GRANDS-PROJETS'
New-PathShare -Path 'D:\PARTAGES\commun_centre' -Name 'commun_centre'
New-PathShare -Path 'D:\PARTAGES\controle_gestion_44' -name 'controle_gestion_44'
New-PathShare -Path 'D:\PARTAGES\Ancien' -name 'Nouveau'
)

Foreach ($Data in $DatasFromWMI)
{
$Newpath = '{0}\{1}' -F (Split-Path $Data.Path -parent),$Data.Name
Write-Host \"Create DFS avec '$Newpath'\"
}
# Create DFS avec 'D:\PARTAGES\GET\cablage'
# Create DFS avec 'D:\PARTAGES\GET\CENTRE-GRANDS-PROJETS'
# Create DFS avec 'D:\PARTAGES\commun_centre'
# Create DFS avec 'D:\PARTAGES\controle_gestion_44'
# Create DFS avec 'D:\PARTAGES\Nouveau'
[/code:1]

Tutoriels PowerShell

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

Plus d'informations
il y a 5 ans 13 heures #28809 par Agrougroum00
Réponse de Agrougroum00 sur le sujet Re:Recherche et remplacement
Merci pour ta réponse détaillée :)

Je vais tester ça!

Par contre je ne vois pas comment passer ma commande [code:1]Get-WmiObject -Class Win32_Share -ComputerName ($Server +\".domain.com\"«») | Select-Object Path, Name
[/code:1] en tant que paramètre, afin que $DatasFromWMI puisse avoir les valeurs :s

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

Plus d'informations
il y a 5 ans 12 heures #28810 par Laurent Dardenne
Comme ceci:
[code:1]
$DatasFromWMI=Get-WmiObject -Class Win32_Share -ComputerName ($Server +\".domain.com\"«») | Select-Object Path, Name
[/code:1]
L'appel Select-Object Path, Name crée le même type d'objet.

Tutoriels PowerShell

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

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