处理一个脚本,该脚本从用户输入中获取FQDN,然后输入该服务器和域名,并将其添加到pattern之后的文本文件中ID=
。
有一个文本文件,里面是一行ID=[some number]
。我希望有一个cmdlet[some number]
可以将找到的cmdlet更改为ID=
我定义的2个变量。
Ansgar的解决方案:
$name,$domain,$rest = $serverName.split('.',3)
(get-content 'c:\file.txt') -replace "(ID=).*", "`$1$domain$name" | set-content 'c:\file.txt'
使用Powershell v2。
只需用变量的内容替换该数字,然后将文本写回到文件中:
(Get-Content 'C:\file.txt') -replace '(ID=)\[\d*\]', "`$1$domain$name" |
Set-Content 'C:\file.txt'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句