Share via

Move-Item - Powershell using ForEach

Danny T 21 Reputation points
2021-03-20T13:46:26.02+00:00

What I am trying to do is the following...

I have a .txt file with a list of files which I want moved to a different location. So for example...

The source directory has dll files but I only want to move a subset of them not all, which I have already populated in the text file. This will move them to a destination directory.

I'm still learning powershell so any advice would be great...

Thanks :)

Windows for business | Windows Server | User experience | PowerShell

Answer accepted by question author

Rich Matheisen 48,116 Reputation points
2021-03-20T15:16:07.403+00:00

If the full path name of the DLLs are in the file then this should work:

Move-Item -Path (Get-Content x:\directory\file-with-dll-names.txt) -Destination y:\new-directory

If you have only the DDL name, and not the full path, in the file then this should work:

Get-Content x:\directory\file-with-dll-names.txt |
    ForEach-Object{
        Move-Item -Path "I:\source-directory\$_" -Destination y:\new-directory
    }

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.