比较对象删除部分资源



我有代码

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

我得到的东西看起来像这样

\ServerpathpathConfig.Current.Running.rt-1.ci.cou.txt

我只想要它的一部分 = rt-1.ci.cou 在我的$relault .txt文件中

#Set a variable, Path, with the full string you're looking at
[string]$Path = '\ServerpathpathConfig.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

最新更新