I am trying to grab certain logs from a folder and copy them to my device. The code works, but the output is not what I expect (the other three log files are in the Logs folder). I would just like to have my three files appear. The output I get it below. The console complains about the directory already existing, but that is because it is created prior to my loop I think?
$filename = $env:COMPUTERNAME $files = @('CAS.log', 'LocationServices.log', 'AppDiscovery.log', 'CCMExec.log') foreach ($file in $files) { Copy-Item "c:WindowsCCMLogs" -Filter $file -Destination "\REMOTECOMPUTERNAMEc$RemoteLogStore$filename" -Recurse }
The $filename in "\REMOTECOMPUTERNAMEc$RemoteLogStore$filename" is the same for every pass of foreach.
$filename
"\REMOTECOMPUTERNAMEc$RemoteLogStore$filename"
Update $filename in the loop to what you actually want as a name, or just use the values from $files
$files
1.4m articles
1.4m replys
5 comments
57.0k users