Powershell 另一文档中的用户定义字符串

Powershell 另一文档中的用户定义字符串,powershell,Powershell,我需要这个代码的帮助 $name = Read-Host -Prompt 'Input Connection String' powershell -Command "(gc C:\ELK\logstash\bin\logstash.conf) -replace 'localhost:1521', '$name' | Set-Content C:\ELK\logstash\bin\logstash.conf" 我希望用户定义自己的连接字符串,并能够启动脚本再次如果用户胖手指

我需要这个代码的帮助

$name = Read-Host -Prompt 'Input Connection String'
powershell -Command "(gc C:\ELK\logstash\bin\logstash.conf) -replace 'localhost:1521', '$name' | Set-Content C:\ELK\logstash\bin\logstash.conf"
我希望用户定义自己的连接字符串,并能够启动脚本再次如果用户胖手指,不会注意到打字错误。 如果用户输入了一些内容,但记住他想要其他内容,那么脚本将无法工作,因为字符串localhost:1521将不再存在


感谢您的帮助。

请同时阅读要替换的图案和替换:

$pattern=读取主机-提示“输入要替换的内容” $name=读取主机-提示“输入连接字符串” powershell-命令gc C:\ELK\logstash\bin\logstash.conf-替换$pattern,$name |设置内容C:\ELK\logstash\bin\logstash.conf
这是一个选项,只是阅读在第二个字符串?我很抱歉,迟了答复,但你能举个例子,请看我的答案为一个例子。谢谢你,这是我需要的