jamwatn Posted June 2, 2020 Posted June 2, 2020 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...
Chaniel Posted June 4, 2020 Posted June 4, 2020 (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 June 4, 2020 by Chaniel 1
jamwatn Posted June 4, 2020 Author Posted June 4, 2020 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
DJ-1701 Posted June 4, 2020 Posted June 4, 2020 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 } 1
jamwatn Posted June 4, 2020 Author Posted June 4, 2020 Thanks so much that has worked perfectly. Thanks to both of you. I think this has prompted me to learn a bit of Powershell!
Chaniel Posted June 4, 2020 Posted June 4, 2020 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 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now