1
我有這個功能,我希望輸出文件名應該與文件名「_new.log」添加到最後。這是我的劇本。這是行不通的。powershell - 添加一個字符串輸出填充名稱是拋出一個錯誤
Function IIS-CleanUp1($file)
{
Get-Content $file | ? { $_ -match $control -and $_ -notmatch '^\#'} | Out-File $file + "_new.log"
}
IIS-CleanUp1 "u_ex130801.log"
它引發以下錯誤:
Out-File : Cannot validate argument on parameter 'Encoding'. The argument "+" does not belong to the set "unicode,utf7,
utf8,utf32,ascii,bigendianunicode,default,oem" specified by the ValidateSet attribute. Supply an argument that is in th
e set and then try the command again.
At C:\ShiyamTemp\IIS_CCHECK_AUG\IIS.ps1:3 char:79
+ Get-Content $file | ? { $_ -match $control -and $_ -notmatch '^\#'} | Out-File <<<< $file + "_new.log"
+ CategoryInfo : InvalidData: (:) [Out-File], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.OutFileCommand
任何幫助非常感謝:
- Ť
感謝。它解決了這個問題。但它說u_ex130801.log_new.log。它正在做代碼要求它做的事情。我該如何說u_ex130801_new.log – user1666952
@ user1666952 - 什麼是'$ file'?查看方法的更新答案。 – manojlds
太棒了。再次感謝。像魅力一樣工作 – user1666952