是否使用Powershell脚本替换文本文件中的未知字符?

是否使用Powershell脚本替换文本文件中的未知字符?,powershell,Powershell,我正在编写powershell脚本来编辑多个文本文件。所有文本文件都有这样一行 服务器URL=http://localhost:1234 最后4个数字在每个文件中有所不同,但我需要将它们全部更改为9090。我曾尝试使用powershell通配符,如下所示: foreach ($file in $files) { (Get-Content $file).replace('serverUrl=http\://localhost\:????', 'serverUrl=http\://l

我正在编写powershell脚本来编辑多个文本文件。所有文本文件都有这样一行

服务器URL=http://localhost:1234

最后4个数字在每个文件中有所不同,但我需要将它们全部更改为9090。我曾尝试使用powershell通配符,如下所示:

foreach ($file in $files) {
        (Get-Content $file).replace('serverUrl=http\://localhost\:????', 'serverUrl=http\://localhost\:9090') | Set-Content $file
}

但不幸的是,这些都不起作用。有没有办法做到这一点?谢谢您

使用
-replace
regex运算符而不是
String.replace()
方法:

(Get-Content $file) -replace 'serverUrl=http://localhost:\d{4}','serverUrl=http://localhost:9080'