Hi all,
I am new to powershell and want to copy logfiles from one directory, change some contents and write back the changed logfile to a destination directory. My script looks like this: It works fine when I don't include the Set-Content statement. The displayed path and filenames are correct. Executing the set-content statement leads to an error (see blow), also | out-file $outputfile doesn't work. Any help or suggestions are welcome.
function test1
{
param
(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]
$InputPath,
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[string]
$OutputPath
)
process
{
$OutputFile = " "
Get-ChildItem -Path $InputPath\* -Include *.log |
ForEach-Object {
"processing dir \ file: $_"
$FileName = $_.name
"processing File : $Filename"
$OutputFile = $OutputPath+"\"+$FileName
"Output Path & File : $OutputFile"
Get-Content $_ |
ForEach-Object {
$Line = $_
### more procssing here
}
} | Set-Content -Path $OutputFile
}
}
test1 C:\qv\InputLogfiles C:\qv\OutputLogfiles
Set-Content : Could not find a part of the path 'C:\Users\son\'.
In Zeile:33 Zeichen:16
+ } | Set-Content -Path $OutputFile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-Content], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.SetContentCommand
Siegmund Sonntag