Powershell script to copy 2 folders into a user's roaming profile

Hiya,

Our users are running an application called TM1 which on opening is meant to put 2 folders in their profile under the AppData folder. Due to an application bug of seeming to not put the 2 folders in if users are running roaming profiles, we just need a script or process that copies 2 folders from a location into their profile into the AppData . If at all possible to check if the folders are there first and if they are do nothing and if they aren't there, to copy them in.

Is there an easy way of doing this with batch or PowerShell scripts?

Thanks v much
LVL 2
rhiancohenVMware Senior ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThommyCommented:
This might help you further...
Copy file to all users
0
ThommyCommented:
Store your source folders for example in folder TM1AppData

Then you can simply use XCOPY to move them to your AppData-Path

XCOPY "TM1AppData" "C:\Users\USERNAME\AppData\Roaming" /E /C /Q /I /Y

For help with XCOPY: XCOPY /?
0
Justin YeungSenior Systems EngineerCommented:
in powershell, you can easily do that.

Test-path and copy-item

however would you please provide a bit more info such as

source - is it a network location?
destination - roaming profile on a windows shared folder, etc.

so then I can provide a better solution regarding on this by using powershell
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

rhiancohenVMware Senior ConsultantAuthor Commented:
Hiya

We would probably put the source folder as c:\Applix

Destination would need to be \\serverxyz\Profiles\%username%\AppData\Roaming

Thanks for all the help and I will have a look at the other solutions as well. Been a busy day
0
ThommyCommented:
You mentioned 2 folders to be copied into ...\AppData\Roaming!!!

Are these 2 source folders located in c:\Applix, so that its contents should be copied into ..\AppData\Roaming?
0
rhiancohenVMware Senior ConsultantAuthor Commented:
Yes it is a folder called Applix thaT contains a folder called TM1
0
ThommyCommented:
So I assume, that your goal is, to have following folder structure in your roaming profile:

\\serverxyz\Profiles\%username%\AppData\Roaming\Applix\TM1

Is that correct???
0
rhiancohenVMware Senior ConsultantAuthor Commented:
Yes that's correct thanks
0
ThommyCommented:
Just call below Copy-Item command and you will have your Applix source folder replicated to ...\Appdata\Roaming...

Copy-Item -path "C:\Applix" -Recurse -Destination "\\serverxyz\Profiles\%username%\AppData\Roaming" -Container

Open in new window

0
rhiancohenVMware Senior ConsultantAuthor Commented:
Thanks very much for this.

Will it overwrite the folder though everytime someone logs in?
0
Justin YeungSenior Systems EngineerCommented:
you can actually do a test path before execute, and I don't think %username% will work in powershell, it needs to use $env:Username


if (!(Test-path "\\serverxyz\Profiles\$env:USERNAME\AppData\Roaming\Applix"))
{
Copy-Item -path "C:\Applix" -Recurse -Destination "\\serverxyz\Profiles\$env:USERNAME\AppData\Roaming" -Container
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rhiancohenVMware Senior ConsultantAuthor Commented:
Great thanks. I'll give it a go
0
rhiancohenVMware Senior ConsultantAuthor Commented:
Hiya,

I have tested your script and it works great. I just had to make one adjustment which seems to have worked in that when a user logs on, it creates a profile folder called username.V2 so I modified the $env:USERNAME part to $env:USERNAME.V2

if (!(Test-path "\\serverxyz\Profiles\$env:USERNAME\AppData\Roaming\Applix"))
{
Copy-Item -path "C:\Applix" -Recurse -Destination "\\serverxyz\Profiles\$env:USERNAME.v2\AppData\Roaming" -Container
}
 
Thanks very much for your help. Much appreciated
0
rhiancohenVMware Senior ConsultantAuthor Commented:
OK Slight adjustment again with updates in bold - Basically add V2 to both $env and add the folder Applix to the end of the path for the copy-item part

if (!(Test-path "\\serverxyz\Profiles\$env:USERNAME.V2\AppData\Roaming\Applix"))
{
Copy-Item -path "C:\Applix" -Recurse -Destination "\\serverxyz\Profiles\$env:USERNAME.V2\AppData\Roaming\Applix" -Container
}
0
rhiancohenVMware Senior ConsultantAuthor Commented:
Just a quick question...

Why do you put an ! in the script at the very start?

Thanks
0
ThommyCommented:
It's simply the NOT-operator, to test if the destination path does not already exist...
0
rhiancohenVMware Senior ConsultantAuthor Commented:
Thanks Guys. really helpful and always useful to learn more PowerShell and syntax as well.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.