0

j'ai Code-Object supprimer les parties du corps centrale

Compare-Object $str $str1 | foreach InputObject | ft -auto | out-file "$resault" -width 5000 

et je reçois somthing qui ressemble à ceci

\\Server\path\path\Config.Current.Running.rt-1.ci.cou.txt 

et je veux seulement une partie de celui-ci = rt-1.ci .cou dans mon fichier .txt $relault

+0

Comment décidez-vous quelle partie vous voulez? c'est-à-dire quelle est la règle? par exemple. La partie '\\ Server \ path \ path \ Config.Current.Running.' est-elle cohérente, ou cela peut-il varier/existe-t-il au moins une structure cohérente? – JohnLBevan

+0

Est la première partie de votre question, où vous donnez le code pour 'compare-object', etc, pertinente, ou est la question juste:" Étant donné une chaîne comme '\\ Server \ path \ path \ Config.Current.Running .rt-1.ci.cou.txt' comment puis-je le réduire à 'rt-1.ci.cou'?) – JohnLBevan

Répondre

0
#Set a variable, Path, with the full string you're looking at 
[string]$Path = '\\Server\path\path\Config.Current.Running.rt-1.ci.cou.txt' 

#Remove the directory so we're left with just the filename 
[string]$Filename = (Split-Path -Path $Path -Leaf) 
#$FileName: Config.Current.Running.rt-1.ci.cou.txt 

#use regular expressions to capture the text that appears after the 3rd period (`.`) and before the last period. 
$Filename -replace '^[^.]*\.[^.]*\.[^.]*\.(.*)\.[^.]*$', '$1' 
#Output: rt-1.ci.cou