Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, October 23, 2018 6:30 PM
Hello,
We have a huge amount of employee folders and I have a list.txt file with specific file paths of employees who are not with the company. Is there a way with powershell to move all these folders into another path? I was able to move items with the move-item command, but that's only one folder. I'd like to see if there's a way to move specific folders in that directory to another directory. Thank you
All replies (2)
Wednesday, October 24, 2018 12:51 AM
Given a list.txt file with these sample lines:
c:\temp\employees\dave
c:\TEMP\employees\bob
A simple script would be:
get-content list.txt |%{
$Destination = $_ -replace 'c:\temp\employees', 'c:\temp\non-employees' # first string must use \ because of regex.
"Moving $_ to $Destination"
move-item -path "$_" -destination "$Destination"
}
It would output:
Moving c:\temp\employees\dave to c:\temp\non-employees\dave
Moving c:\TEMP\employees\bob to c:\temp\non-employees\bob
Wednesday, October 24, 2018 2:08 AM
Hi,
I agree with Moto.
You can use get-content cmdlet to get employee folder path. Then use foreach-object cmdlet to move these folders to another directory in a loop.
Refer the link below:
/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-6
/en-us/powershell/module/microsoft.powershell.management/move-item?view=powershell-6
Best Regadrs,
Lee
Just do it.