How to get all domain users into an array?

I need to make a script that goes through all members of the Domain Users group and puts them into an array so I can do a for each and create a new folder in \fileserver\users$username\Documents called MFA then drop files into it…

$username has to be their login ID so I think the samaccount value will do this…

I need something like this to get all the users
$users = Get-ADUser -Filter * -SearchBase “OU=Domain Users” | select samaccountname
Is this correct??

Then I want to do something like:
for each user in $users
cd \fileserver\users$username\Documents
mkdir MFA
cd \fileserver\users$username\Documents\MFA
copy files into MFA

It’s getting the users into an array containing their login ID, which I think is their samaccount name

Thank you, Tom

First … please … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Something like this could be a starting point.

$ADGroup = 'sAMAccountName of the desired Group'
$SourceFilesPath = 'Path you want to copy files from'

$ADGroupMemberList = Get-ADGroupMember -Identity $ADGroup

foreach ($ADGroupMember in $ADGroupMemberList) {
    $ADUser = Get-ADUser -Identity $ADGroupMember
    $TargetPath = '\\ComputerName\Share\{0}\Documents\MFA' -f $ADUser.sAMAccountName
    New-Item -Path $TargetPath -ItemType Directory | Out-Null
    Copy-Item -Path $SourceFilesPath -Destination $TargetPath -Recurse

(untested - try with test data first !! :wink: )

I do know how to format code on this forum…real code, that is.
What I posted was mostly air code, very general stuff.
Which I didn’t think was also required to be pre-formatted. :slight_smile:
Meanwhile thank you for helping me get started!! :slight_smile:
Thank you, Tom

You may think of it as a way to be polite with the people willing to help you and make it easier for them to read your question and to easily destinct between text and code. :wink: