title: Copy folder contents using VBScript
body: <p>I am trying to copy the contents of certain folders to another folder using VBScript.</p>
  
  <p>The goal is to enumerate a user's AD groups and then copy specific folder content based on those groups.</p>
  
  <p>I have code, which is currently not working.</p>
  
  <pre><code>Dim Group,User,objFSO,objFolder,source,target,StrDomain
  
  StrDomain = "domain.local"
  FolderBase = "\\domain.local\netlogon\workgrps\icons"
  Set net = CreateObject("wscript.network")
  Struser = net.username
  target = "\\fs1\users\"&amp;net.username&amp;"\Desktop\AppIcons\"
  
  DispUserInWhichGroup()
  
  Function DispUserInWhichGroup()
  
  On Error Resume Next
  
  Set objFSO=CreateObject("Scripting.FileSystemObject")
  Set User = GetObject("WinNT://" &amp; strDomain &amp; "/" &amp; strUser &amp; ",user")
  
  For Each Group In User.Groups
  
  source = FolderBase &amp; Group.name
  
  Set objFolder = GetFolder(source)
  
  For Each file in objFolder.Files
  objFSO.CopyFile source &amp;"\"&amp; file.name, target&amp;"\"&amp;file.name
  Next
  
  Next
  
  End Function
  </code></pre>
  
  <p>This has been cobbled together from various sources, and I'm sure most of it is right, I just can't get it working completely.</p>
  
  <p>Any assistance would be great.</p>
  
  <p>Cheers.</p>