Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
}

What shows up in RemoteLogStore

question from:https://stackoverflow.com/questions/65888144/powershell-recursively-writing-to-the-same-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

The $filename in "\REMOTECOMPUTERNAMEc$RemoteLogStore$filename" is the same for every pass of foreach.

Update $filename in the loop to what you actually want as a name, or just use the values from $files


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...