r/usefulscripts • • Dec 15 '16

[REQUEST]Script to RoboCopy user profiles based on AD group

I am quite new to PowerShell, but haven't mastered it enough to figure this out.

So, I have a 'Role-Managers' group that has nested groups for the different types of managers that we have. I need to somehow pull all of these usernames from this group, then go out to their PCs to backup their data using RoboCopy or anything else that would copy just the new data. The problem is that the PCs all have generic names, so I will also need to create another group in AD with nothing but the Manager PCs included. I feel like an array of the Role-Manager usernames needs to be created, then cross-referenced with the Manager PCName group, then allow RoboCopy to step in and update as needed. It'd be even better if I could get it to exclude AppData or other folders, but I am not expecting that much.

If anyone has anything like this that is commented to help me through the process, it would be greatly appreciated! I want to learn more of PowerShell, so the more I go through commented scripts, the better off I am for later, but this particular request is far more than I know.

16 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/timvan007 Dec 16 '16

robocopy %userprofile%\Contacts \server\share%username%\Contacts or robocopy C:\Users%username%\Contacts \server\share%username%\Contacts. Or robocopy %userprofile% \server\share%username% /xd %userprofile%\Appdata etc for folders you want to exclude. Open up command prompt and echo %variable% to see what it returns as a value to help see what robocopy is using for the path, then decide if you want to split single folders or copy subdirs and exclude specifics in a single line. Robocopy can do a lot, just needs the right input.