Copy file to all users in a Specific OU using powershell

Rob Slack 21 Reputation points
2022-03-28T14:06:06.793+00:00

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

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2022-03-28T15:18:00.683+00:00

    See if this works any better:

    $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
        }
    

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-03-28T14:20:56.873+00:00

    What property of the user object do you want to use? "Name", "samAccountName", "DisplayName", or something else?

    It looks like you're only copying a single file. Why are you using the -Recurse switch in the Copy-Item cmdlet?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.