• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4074
  • Last Modified:

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
0
rhiancohen
Asked:
rhiancohen
  • 9
  • 6
  • 2
2 Solutions
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now