PS – Move files in file list

Problem

You want to move files that are listed in a text based file

Solution

This worked for us. Place into a PS file. Remove the -Whatif after testing

$aryfiles = Get-Content “\\server\apps\1to1100.txt”
$sourceDir = “\\server\apps\PRD-Purge\WBS”
$destinationDir = “\\server\apps\PRD-PurgeMove”
$sourceFiles = Get-ChildItem -Path $sourceDir -Recurse -Include $aryfiles |
Select-Object -ExpandProperty FullName
foreach ($sourceFile in $SourceFiles)
{
Move-Item $sourcefile -Destination $destinationDir -WhatIf
}

Reference
Taken from: http://powershell.com/cs/forums/t/20656.aspx

Leave a Reply