Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Group Policies / Copy Files and Folders to User Computers via GPO

March 15, 2024 Active DirectoryGroup PoliciesWindows 10Windows 11Windows Server 2019

Copy Files and Folders to User Computers via GPO

You can use Group Policies to copy specific files and folders to user computers in the Active Directory domain. You can place files on the Desktop, in a particular user profile directory, or any other folder on a local drive. With GPO, you can automatically copy and update various configuration files, INI files, app executables (EXEs), DLLs, or scripts from a shared repository.

Contents:
  • Copying Files Using Group Policy Preferences
  • How to Copy Folders and Files with GPO Startup Script?

Copying Files Using Group Policy Preferences

For example, I want to copy two files (app.exe and settings.xml) to the Desktops of some Active Directory domain users.

Create a shared folder to store the source files you want to copy to users’ computers. It may be a shared SMB folder on a file server or the SYSVOL directory on a domain controller (this folder is automatically replicated between all DCs in the domain using DFS, it is convenient to use it since it helps to reduce the load on the WAN links). I have placed the files in the Sysvol folder \\woshub.com\SYSVOL\woshub.com\scripts\CorpApp. Make sure that the Authenticated Users group has read permissions on this folder.

grant read permissions on source folder for Authenticated Users

  1. Create a new Active Directory security group (CorpAPPUsers) using the Active Directory Users and Computers snap-in (dsa.msc). You can create a group using this PowerShell cmdlet: New-ADGroup CorpAPPUsers -path 'OU=Groups,OU=DE,dc=woshub,DC=com' -GroupScope Global -PassThru –Verbose Add users to the group to whose desktop you want to automatically copy files through the GPO: Add-AdGroupMember -Identity CorpAPPUsers -Members asmith, bmuller, tweber
  2. Open the Group Policy Management console (gpmc.msc);
  3. Create a new GPO object (CopyCorpApp) and link it to the OU that contains users’ computers; create new copycorpapp GPO
  4. Edit the GPO settings;
  5. Expand the following Group Policy Preferences section: User Configuration –> Preferences -> Windows Settings -> Files;
    If you need to copy files to computers regardless of logged-in users, it is better to use a similar policy in the Computer Configuration section of GPO.
  6. Select New –> File;
  7. Specify the source file in the shared folder and the target path on the computer you want to copy the file to. If the specified path does not exist, it will be automatically created. Be sure to specify the full name of the target file (if you just specify a target directory, you will receive an “access denied” error when copying the file).
    You can select the specific file name here or copy all files from the source directory at once by specifying a wildcard character *.
  8. 4 actions are available for copying files using GPO:
    Create – file is copied to a target directory only if it doesn’t exist there;
    Replace – the target file on a user’s computer is always replaced by the source file. If the source file is large, it will be copied every time the GPO is updated, which can cause a high network load. If you only want to replace the file once, enable the ‘Apply once and do not reapply’ option on the Common tab;
    Update (a default policy) – if a file already exists and the source and destination files are different, it is not replaced with the source file (only attributes will be replaced). If the file does not exist, it will be copied;
    Delete – delete the target file.GPO: Copy file from shared network to user Desktop
  9. You can select a specific folder on a computer as a target directory or use environment variables. To copy files to the current user’s Desktop, use %DesktopDir%
    You can view the full list of the environment variables available in GPP by pressing  F3. group policy preferences system defined variable F3Here is a list of environment variables that can be used as destination folders when copying files using  GPO:
    %AppDataDir%Current user’s Application Data folder
    %CommonAppdataDir%Application Data folder of all users
    %CommonDesktopDir%Desktop of all users
    %CommonProgramsDir%The Programs directory of all users.
    %CommonStartMenuDir%Start Menu folder of all users
    %CommonStartUpDir%Startup directory for all users
    %ComputerName%NetBIOS computer name
    %DesktopDir%Current user Desktop
    %DomainName%Current domain name
    %LocalTime%Local computer time
    %LogonDomain%Current user’s domain
    %LogonServer%The name of the domain controller on which the user is authenticated to
    %LogonUser%Current user name
    %NetPlacesDir%User’s My Network Places Directory
    %ProgramFilesDir%Program Files directory
    %ProgramsDir%User’s Programs directory
    %RecentDocumentsDir%User’s Recent Documents directory
    %SendToDir%User’s Send directory
    %StartMenuDir%Start Menu of the current user
    %StartUpDir%Current user Startup folder
    %SystemDir%Windows directory
    %SystemDrive%The drive on which the operating system is installed
    %TempDir%User Temp folder
    %WindowsDir%Windows directory

  10. To copy files to the desktops of the specific users, open the Common tab in the policy settings, enable the Item-Level Targeting option, and click Targeting;
  11. In the next window, you can select more options for how to apply the GPO. In my case, I would like to restrict the policy to CorpAPPUsers group members only. To do it, click New Item -> Security Group and specify the domain user group; Item-Level Targeting - apply GPO to specific group
  12. Since we’ve linked the GPO to an Organizational Unit containing computer objects (not user accounts), you need to enable the GPO loopback processing mode. Enable the option Configure user Group Policy loopback processing mode = Merge in Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy; enable the policy : Configure user Group Policy loopback processing mode
  13. Then update Group Policy settings on client computers (gpupdate /force or log off and log on again), and make sure the two files were automatically copied to the user’s Desktop.  copy files to user desktop via group policy

In this way, you can copy scripts, application executable files, or system tools (PsTools, iperf, Portqry, etc.) to user computers. You can copy a file to Program Files and place a shortcut to it on the desktop via GPO.

If you need to copy a directory to a user’s computer, you need to use the Group Policy item from Computer (User) Configuration –> Preferences -> Windows Settings -> Folders section. This option allows you to create a directory on a target computer. You can then copy the source files to this directory as described above.

copy folder with GPO

If the files are not copied to users’ computers, you can use the gpresult.exe tool to figure out why the Group Policy is not being applied. To get detailed logs of GPO file copy operations, you can enable the log under Computer Configuration -> Policies -> Administrative Templates -> System -> Group Policy -> Logging and Tracing. Enable the Configure Files preferences logging and tracing option and select the Informational, Warning, and Errors mode in the policy settings.

enable gpo file preferences logging

Now you can track all events and errors related to copying files through GPO on clients in the Event Viewer -> Application log. Enable the filter by the Group Policy Files source.

In my case, an Event ID 4098 error appeared on a user’s computer when copying files via GPO:

The user '%CommonDesktopDir%' preference item in the 'CopyCorpApp {GPO_GUID}' Group Policy Object did not apply because it failed with error code '0x80070005 Access is denied.' This error was suppressed.

gpo copy file error: 0x80070005 access denied event id 4098

This issue was resolved by granting NTFS read permissions to files in the source directory to the Authenticated Users group.

How to Copy Folders and Files with GPO Startup Script?

Note that Group Policy Preferences do not allow you to copy an entire directory with all child subfolders and files. If you need to copy a folder with a large number of files, or you want the contents of the target user folders to always be updated when any file in the source is updated, you can make a simple logon script and run it through the GPO.

Let’s create a GPO startup script to copy all new (and changed) files from the source directory to users’ computers:

  1. Create a batch file in Sysvol:
    CopyCorpApp.bat
    IF EXIST "C:\CorpApp" EXIT
    MD "C:\CorpApp"
    xcopy \\fs01\Sources\CorpApp\*.* C:\CorpApp /e /y /k /r /d /i
    In some cases, it is preferable to use the more powerful robocopy command to copy files.
    batch script: copy new and changed files from shared folder on Windows
    This script will copy the entire directory structure and all files with attributes. Only new or changed files are copied. This means that every time you run the script if there are no changes in the source directory, the xcopy command will not overwrite the files.
  2. Create a new GPO (as described above) and assign it to the OU with users’ computers;
  3. Expand Computer Configuration -> Policies -> Windows Settings -> Scripts (Startup/shutdown). Select Startup;
  4. Click the Add button and specify the UNC path to your script on SysVol;run gpo startup batch script
  5. Restart the user’s computer and make sure that the source folder was successfully copied.copy folder with subfolders and files
8 comments
11
Facebook Twitter Google + Pinterest
previous post
How to Install and Configure Squid Proxy Server on Linux
next post
How to Install .NET Framework 3.5 on Windows 11/10 and Windows Server

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Remove ‘Your License isn’t Genuine’ Banner in MS...

April 21, 2025

8 comments

Demitri November 22, 2021 - 12:50 pm

thanks, this is can work, also you can easily use Gs Richcopy 360 or GoodSync to do this job directly

Reply
djoeksanovic November 21, 2022 - 8:26 am

I want to copy some folders from our fileserver instead of one file, how to do that_
here you are talking about 1 specific file.

Reply
admin November 22, 2022 - 8:54 am

You can create multiple items in a GPO. One for each file.
If there are a lot of files in the source dir, it’s easier to make a logon script with the copy/xcopy command

Reply
PK January 6, 2023 - 5:56 pm

Try this..

xcopy \\fs01\Sources\CorpApp C:\ /e /y /k /r /d /i

Yt will copy entire CoreApp folder in C drive

Reply
Kevin Merritt October 7, 2023 - 11:19 am

I have a question for you, I am using the GPO option, and if I user the Folder and File option, I use the %LogonUser% but I have several users Profiles showing as username.domain and this %LogonUser% then does not work. Any thoughts?

Reply
Guilherme Oliveira November 30, 2023 - 2:37 pm

Hello,

I created the script as shown, but when running via GPO it only creates the “C:\orant” folder as I want, but the contents of the folder are not copied.

If I run the script manually it works perfectly.

What could it be?

The GPO is for a computer and I also enabled “Always wait for the network at computer startup and logon”

Reply
admin January 16, 2024 - 6:17 am

Did you run the script on behalf of the system or user account (User or Computer Configuration section of the GPO)?
Check the permissions on the source files. In most cases, permissions must be granted to Authenticated Users group.

Reply
BR0KK85 March 4, 2025 - 2:24 pm

I can get a Link in Edge to be put inside of the default user, so that any user that logs on to the server gets that link on their desktop.

I can’t hoever get a shortcut to be put onto the desktop of a specific user. These gpos simply will not apply.

Tried everything that the GPO offers besides a copy script.

hmm anyone have a soulution to this ?

Thank you

There must be a better solution out ther for this besides logon scripts…

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure Google Chrome Settings with Group Policy
  • Get-ADUser: Find Active Directory User Info with PowerShell
  • Allow Non-admin Users RDP Access to Windows Server
  • How to Find the Source of Account Lockouts in Active Directory
  • How to Disable or Enable USB Drives in Windows using Group Policy
  • Get-ADComputer: Find Computer Properties in Active Directory with PowerShell
  • Configuring Proxy Settings on Windows Using Group Policy Preferences
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top