我有代码
Compare-Object $str $str1 | foreach InputObject | ft -auto | out-file "$resault" -width 5000
我得到了一些看起来像这样的东西
\\Server\path\path\Config.Current.Running.rt-1.ci.cou.txt
我只想要其中的一部分 = rt-1.ci.cou 在我的$relault
.txt 文件中
我有代码
Compare-Object $str $str1 | foreach InputObject | ft -auto | out-file "$resault" -width 5000
我得到了一些看起来像这样的东西
\\Server\path\path\Config.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 = '\\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