Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否使用Powershell脚本替换文本文件中的未知字符?_Powershell - Fatal编程技术网

是否使用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'