I just started looking into PS, so my knowledge on PS is close to none.I need a PS script to 1. look into a text file on C:\ that contains folder names.2. use that text file and see if some of those folders are in location A (D:\Folder1\folder2)3. move those folders that exists in the text file and location A to location B (D:\Folder1)Thank you in advance.
Hi there
What about something like this?
$text = gc C:\foldernames.txt$dir = Get-ChildItem D:\Folder1\folder2foreach ($item in $text) { foreach ($folder in $dir) { if ($folder.name -like $item) { Move-Item "D:\Folder1\folder2\$item" 'D:\Folder1' Write-Host "Folder $item moved successfully" [array]$totalitems += $item break } } }
"""Folders moved: $totalitems"
You will also have a variable $totalitems with a collection of the folders that were successfully moved.
Hope it helps.
D.
Thank you I'll give it a try.