使用powershell命令替换字符串

Read-Host    获取用户输入值
Write-Host   输出回显

$newName = Read-Host "Please input the new name for the string 'test', leave as default, press Enter:"
Write-Host "Processing..."
$newLine = [System.Environment]::NewLine
$dir = (Get-Location).Path+"\"
$file = $dir+"test.txt"
$a += Get-Content $file
if ($newName.Trim() -ne ""){
$a | foreach-object {$_ -replace "test"$newName} | Set-Content -path output.txt
}else{
$a | Set-Content -path output.txt
}
Write-Host "Success"
posted @ 2011-12-13 16:49  Simon_Chen  阅读(1080)  评论(0编辑  收藏  举报