0

I have multiple files in a folder (C:\webfix) the folder has 23 items including random files and folders.

I have 70+ folders I need to push these files out to. Each folder looks like this: C:\saas\CU01313\wwwroot\

C:\saas\CU01316\wwwroot\

C:\saas\CU08453\wwwroot\

etc. etc.

The destination is all the same minus the CU0* part.

I would like to be able to mass move the 23 files/folders to each of these destinations, but I have not been able to figure out how.

After some research, I found that I might be better off using a 'foreach' loop command?

I have been trying to accomplish this in Powershell.

I have tried a couple of things which I can show the code below for. The first "script" uses the Involk-Expression command which I can get to work if I do it one by one. I have not been able to figure out how to "Wild Card" that \CU0*\ part.

First thing:

Invoke-Expression -Command "robocopy C:\webfix\ 'C:\saas\TT08931\wwwroot\' /e /b /COPYALL /MT:8 /r:2 /log:C:\log\log.txt "

If anyone could give me a hand with this I would be very grateful. Thank you very much!

  • it looks like you are trying to run CMD internal commands in a powershell session. you cannot do that since the internal CMD.exe commands are _internal to CMD.exe_ and don't exist in powershell.exe or in the powershell ISE. [*grin*] – Lee_Dailey May 23 '19 at 01:03
  • I did try the second one as a .bat and it did not work either. – Chuck Coggins III May 23 '19 at 01:19
  • 1
    did you try it in a new CMD.exe window? also, you seem to want this in batch, so why don't you change the tags to indicate that - and remove the powershell tag since you are not using powershell? – Lee_Dailey May 23 '19 at 01:52
  • I removed the CMD stuff and kept it strictly Powershell related and updated the keywords. – Chuck Coggins III May 23 '19 at 13:15
  • thank you for the fix! [*grin*] i see that you have you answer now ... excellent! – Lee_Dailey May 23 '19 at 16:22

1 Answers1

0

Figure out a way to put all the CU0xxxx foldernames in a text file. Then do something like this.

$folderlist = get-content C:\temp\Folderlist.txt

foreach ($folder in $folderlist)
{
    Copy-Item -Path  "C:\Webfix\*" -Destination "C:\saas\$folder\wwwroot\" -Recurse
}
Sid
  • 2,586
  • 1
  • 11
  • 22
  • You can get the names of all the folders like this: `(Get-ChildItem C:\saas -Directory).Name | out-file C:\temp\Folderlist.txt` – Sid May 23 '19 at 03:54
  • Thank you both! I really appreciate it. I bought a Powershell Udemy class last night and I need to start learning this so I don't need to ask so many questions. – Chuck Coggins III May 23 '19 at 13:17