0
如何編輯word文檔?在htm文件中用%MyVariable%替換%variablename%
SET /p MyNewPig="Enter My New Pig's Name: "
POWERSHELL(Get-Content c:\temp\test.htm) -replace '\%MyNewPig%\]', '%MyNewPig%' | Set-Content c:\temp\test.htm
如何編輯word文檔?在htm文件中用%MyVariable%替換%variablename%
SET /p MyNewPig="Enter My New Pig's Name: "
POWERSHELL(Get-Content c:\temp\test.htm) -replace '\%MyNewPig%\]', '%MyNewPig%' | Set-Content c:\temp\test.htm
就個人而言,我想創建一個小的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%"
我有兩個文件各一他們使用類似的信息和變量。我需要從用戶輸入中收集變量,並在其中一個文檔中更改超過50個變量的名稱。什麼方法最好用於替換一個文檔中的變量而不是下一個? – Underdog