PowerShell – Copy Files from Source to Destination

It may be more common than you think for a ConfigMgr admin to not have access the Primary site server.

When it does happen, you’ll wonder how to get the logs which can help you troubleshoot issues in the environment.

In my case, I had to get my hands on the ConfigMgr log files so I started looking for a script that would copy the Logs folder (SOURCE) from C:\Program Files\Microsoft Configuration Manager\Logs\ or wherever you have installed ConfigMgr, and paste the Logs into a network share that’s accessible by whoever is running the script at \\FileServer\CMAdmin\Logs\ (TARGET).

You have 2 options here:
1. Learn PowerShell and gain knowledge to make your life easier
2. Cheat and search the Internet for a script that does the job (this can be risky if you don’t understand what the script is doing, for Production and for your job!)

Here are 5 lines of PowerShell that will get the job done for you, which I found here:

$TimeStamp = get-date -f yyyyMMddhhmm
$Destination = "\\FileServer\ConfigMgr\Logs\" + $TimeStamp
$Source = "C:\Program Files\Microsoft Configuration Manager\Logs"
New-Item -ItemType directory -Path $Destination -Force
Copy-Item -Path $Source*.* -Destination $Destination -Force

Leave a Reply

Your email address will not be published. Required fields are marked *