2017-02-03 10 views

答えて

2

、私は例えば、小さなPowerShellスクリプトを作成したい:例えば、

param ([Parameter(Mandatory=$true)] [String] $file = '', 
     [Parameter(Mandatory=$true)] [String] $search = '', 
     [Parameter(Mandatory=$true)] [String] $replace = '' 
    ) 

[Int32] $Local:intRc = 0; 

try { 
    (Get-Content -LiteralPath $file).replace($search, $replace) | Out-File -LiteralPath $file; 
    } #try 
catch [System.Exception] { 
    Write-Host -Object ('ERROR : Exception was "{0}".' -f $_.Exception.Message); 
    $intRc = -1; 
    } #catch 

exit $intRc;  

を...そしてそれを呼び出す:

%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -file c:\xxxxxx\script.ps1 -file c:\yyyyy\test.txt -search "%OLD_NAME%" -replace "%NEW_NAME%" 
+0

を私は2つの文書や各1を持っています同様の情報と変数を使用しています。私は、ユーザーの入力から変数を収集し、ドキュメントのうちの1つだけで50を超える変数の名前を変更する必要があります。 1つの文書の変数と次の変数の変数を置き換えるのにどの方法が最も適していますか? – Underdog

関連する問題