此脚本有效,我想对其进行压缩,因此,如果我添加更多行来查找和替换文件中的文件,则不会多余。
Get-ChildItem C:\Users\JonSa\Desktop -Filter callcounts.xml | Foreach- Object{
(Get-Content $_.FullName) |
Foreach-Object {$_ -replace "@aXXXXX.ac1.vbspbx.com", ""} |
Set-Content $_.FullName
}
Get-ChildItem C:\Users\JonSa\Desktop -Filter callcounts.xml | Foreach- Object{
(Get-Content $_.FullName) |
Foreach-Object {$_ -replace "sip:", ""} |
Set-Content $_.FullName
}
我希望用更少的行来完成此操作,从而为更多的参数留出空间。
答案 0 :(得分:0)
Get-ChildItem
和ForEach-Object
-raw
参数时,您可以将替换应用于整个文件-replace
。|
(或)-replace
运算符省略空替换(不是使用.replace()
方法)$File = 'C:\Users\JonSa\Desktop\callcounts.xml'
(Get-Content $File -raw) -replace '@aXXXXX.ac1.vbspbx.com|sip:' |
Set-Content $File