Jump to content

Recommended Posts

Posted

Hi there,

 

Hoping for a robocopy guru to help us please.

 

I'm hoping to copy the following files to a new share:

 

U:/Home/USERNAME/My Favourites

to

 

U:/StaffHome/USERNAME/My Favourites

 

Please don't ask why we are having to do this task, it wasn't my choice and I would have not done it like this!!

 

I have 200+ users wanting their favourites...

Posted (edited)

You could just do the following in Powershell;

 

$usernames = Get-Content

 

ForEach($line in $usernames){

$oldhome = "\\fileserver\home\$line\My Favourites"

$newhome = "\\fileserver\staffhome\$line\My Favourites"

robocopy $oldhome $newhome /E /W:1 /R:1

 

 

 

 

 

Adjust the robocopy command as you need. Obviously test it on a test account first.

Edited by Chaniel
  • Thanks 1
Posted

Thankyou very much for taking the time to do that. I don't know Powershell at all. Sadly I try to run it and I get:

 

At C:\Temp\favourites.ps1:8 char:1+ {+ ~Missing closing '}' in statement block.At C:\Temp\favourites.ps1:3 char:29+ ForEach($line in $usernames){+ ~Missing closing '}' in statement block. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : MissingEndCurlyBrace

Posted
You could just do the following in Powershell;

 

$usernames = Get-Content

 

ForEach($line in $usernames){

$oldhome = "\\fileserver\home\$line\My Favourites"

$newhome = "\\fileserver\staffhome\$line\My Favourites"

robocopy $oldhome $newhome /E /W:1 /R:1

 

 

 

 

 

Adjust the robocopy command as you need. Obviously test it on a test account first.

 

Thankyou very much for taking the time to do that. I don't know Powershell at all. Sadly I try to run it and I get:

 

At C:\Temp\favourites.ps1:8 char:1+ {+ ~Missing closing '}' in statement block.At C:\Temp\favourites.ps1:3 char:29+ ForEach($line in $usernames){+ ~Missing closing '}' in statement block. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : MissingEndCurlyBrace

 

Well I can tell you what's wrong... there is no } at the end of the ForEach statement. That's why I always format my code like the following, makes it easier to spot issues with those brackets.

 

$usernames = Get-Content 

ForEach($line in $usernames)
{
   $oldhome = "\\fileserver\home\$line\My Favourites"
   $newhome = "\\fileserver\staffhome\$line\My Favourites"
   robocopy $oldhome $newhome /E /W:1 /R:1
}

  • Thanks 1
Posted

Thanks so much that has worked perfectly. Thanks to both of you.

 

I think this has prompted me to learn a bit of Powershell!

Posted
Well I can tell you what's wrong... there is no } at the end of the ForEach statement. That's why I always format my code like the following, makes it easier to spot issues with those brackets.

 

$usernames = Get-Content 

ForEach($line in $usernames)
{
   $oldhome = "\\fileserver\home\$line\My Favourites"
   $newhome = "\\fileserver\staffhome\$line\My Favourites"
   robocopy $oldhome $newhome /E /W:1 /R:1
}

Yeah... when I used the

 blocks it took all the formatting/line breaks out and when editing to try to fix, clearly I deleted the last curly bracket at the end! Ta for fixing
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...