Home > OS >  Copy file to all users in a Specific OU
Copy file to all users in a Specific OU

Time:03-31

I want to copy a file to all users in a specific OU using powershell (My knowledge is not great and have just tried amending stuff I have found on google)

So this is what I have tried

$Source = '\\\FS1\D$\Component 3 Skills log template.docx'

$users = Get-ADUser -Filter * -SearchBase 'OU=Drama,OU=ComputerBasedExams,OU=TAW100STUDENTS,OU=TAW100,DC=something,DC=co,DC=uk'

$Destination = '\\\FS1\\Homes\taw100students\'

foreach ($i in $users){
    {Copy-Item $Source -Destination $Destination\\$i -Recurse}

I do not get any error, but the files do not copy either

CodePudding user response:

If you aren't sold on using powershell for this i would recommend using Group Policy to push files to a group of user or machines. Here's a good tutorial on how to use gpo: http://woshub.com/copy-files-on-all-computers-group-policy/

CodePudding user response:

I had some help elsewhere and this code worked

$Source = '\\FS1\D$\Component 3 Skills log template.docx'

$Destination = '\\FS1\Homes\taw100students'

$sb='OU=Drama,OU=ComputerBasedExams,OU=TAW100STUDENTS,OU=TAW100,DC=something,DC=co,DC=uk'

Get-ADUser -Filter * -SearchBase $sb |

 ForEach-Object{
     $dest = "{0}\{1}" -f $Destination, $_.Name
     Copy-Item $Source -Destination $dest

 }
  • Related