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
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 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
        }
    

0 additional answers

Sort by: Most helpful

Your answer

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