简体   繁体   中英

How to debug why the replacing of multiline is not working in this PowerShell script?

I wrote this code in PowerShell script but for some reason it's not working. The program itself is working but the replacing of multiline is not working - can anyone shed any light as to why?

Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | 
Out-Null

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "SCD (*.scd)| *.scd"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}

$inputfile = Get-FileName "C:\Users\Mr.Nephilim\Desktop\ABB"
#$inputdata = get-content $inputfile

#$configFiles = Read-Host 'Enter Complete directory to file'
(Get-Content $inputfile) |
Foreach-Object { 
$_ -replace  '(?ms)^\[\t\n\v\f\r ]<Private type="ABB.*?</Private>', ''
   #-replace '<Terminal .+\/>', '' `
   #-replace '<Terminal .*?>\s<\/Terminal>', '' `
   #-replace '<Private type=\"ABB(.|\n)*?<\/Private>', '' `
   #-replace '<ConnectivityNode.*?>(.|\n)*?<\/ConnectivityNode>', ''
   #-replace '<Terminal .+/>', '' `
   #-replace '<Private type="ABB.*?>.*?</Private>', '' `
   #-replace '<Terminal .+>', '' `
   #-replace '<Private type=\"ABB.*?>', '' `
   #-replace '<esld:.*?>', '' `
   #-replace '<esld:.*?\/>', '' `
   #-replace '</esld:.*?>', '' `
   #-replace '</Private.*?>', '' `
   #-replace '</Terminal.*>', '' `
   #-replace '<ConnectivityNode.*?>', '' `
   #-replace '</ConnectivityNode.*?>', '' 

} |

Set-Content $inputfile

(GC $inputfile)|?{$_.Trim(" `t")}|SC $inputfile

(?s)(.|\\s).*? using this way it can be done...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM