Copying files to all of the the user profiles is a snap with PowerShell.
It’s one of the more common questions that I’m asked, so I thought I’d get a blog post written about it so that people have something to reference.
Copying Files to All User Profiles
If you have ever used a computer, then you probably already know how to copy files. Copying files with PowerShell, however, makes things a great deal more interesting and fun.
Here are a few quick examples. They will copy single files or entire folder structures.
In my examples, I’m copying into the %USERPROFILE%\AppData\Local folder of every user on a computer. Feel free to modify these scripts to copy any files to any location that works best for you.
Copying a single file (Get-ChildItem)
$Source = '\\FileShare\FancyConfigurationFiles\Config.xml'
$Destination = 'C:\users\*\AppData\Local\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force}
Copying a directory and its contents recursively
$Source = '\\FileShare\FancyConfigurationFiles\'
$Destination = 'C:\users\*\AppData\Local\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force -Recurse}
Copying the contents of a directory recursively
$Source = '\\FileShare\FancyConfigurationFiles\*'
$Destination = 'C:\users\*\AppData\Local\'
Get-ChildItem $Destination | ForEach-Object {Copy-Item -Path $Source -Destination $_ -Force -Recurse}
That’s it. It’s very simple and straightforward. The $Source is the file or folder that you wish to copy. The $Destination is the target folder that you wish to copy to.
Let’s take our script and combine it with PDQ Deploy. We will be be copying files to all of our machines in no time!
Using PDQ Deploy to run PowerShell scripts remotely
Copying files to all your machines is a piece of cake with PDQ Deploy. We normally recommend using our File Copy step for copying files to your targets. The
wonderful thing about using a PowerShell script is that it allows you to take copying files to a whole new level.
Renaming files after copying? Yep.
Dynamic creation of files? Yep.
Copying files based on name, date, etc? Double yep.
If you can dream it up, you can probably do it with PowerShell. Get Creative!
Using PowerShell with PDQ Deploy
Here’s a quick overview of how to deploy your new PowerShell script.
Create a package
Add an install step to the package
Add your PowerShell script to your install step
Deploy your package to your computers
For more detailed information, you should check out our videos. Here’s one of our awesome videos that shows how to add PowerShell scripts to a package.
Our videos are very helpful and provide tons of great tips. Plus, Shane has an amazing beard that some believe can control the weather.
Creating a package
Creating a package using our new script is super easy. All that you need to do is create a package with an Install Step. Then, you just need to point the Install File to your script.
Deploying a Package
We can now deploy our new package to any targets. The PowerShell script will run on the targets that you deploy to.
While you’re waiting for your deployments, go get yourself a drink and pat yourself on the back. You just saved yourself a ton of manual effort. Way to go!
Extra features
Adding machines manually is great for quick deployments. For more flexibility and power, you can team up with PDQ Inventory. You can make dynamic collections to deploy packages to targets based off of any number of criteria.
For example, you could create collections based on operating system, installed applications, amount of RAM, etc. There are so many possibilities! You can even use your own custom fields for data unique to your organization.
Additionally, with the Pro and Enterprise versions of PDQ Deploy, you can use more advanced features. You can set up packages to run on a schedule, automatically retry failed machines, email you the results, use Wake-On-LAN, and much more.
Final Notes
Using PowerShell gives you a lot of options for getting files copied. Give it a shot and have some fun! The sky is the limit for what you can do with a script.
There is one thing to keep in mind when using PowerShell with PDQ Deploy. When an install step runs a PowerShell script, it is only going to display whether or not the script was able to execute. In order to see more detailed information, you’ll need to examine the output log of your deployment step.
Go forth and PowerShell!
Did you know that PDQ Deploy has a PowerShell step you can use to deploy your scripts?