$applications = get-content c:\applications.txt
foreach-object {Get-ChildItem "\\sdlcorpwwps01\WiseSharePoint\Projects" -Recurse | Where-Object {($_.PSIsContainer) -AND $_.NAME -eq $applications} | Move-Item -Destination "\\sdlcorpwwps01\smspkgsource$\Archives\Projects"}

Every time I run this command it wants to copy all the folders. I will be using this script to automate our archiving process. Any help?

Thanks! :D
1 Comment   [ + ] Show Comment


  • Hi,
    I'm just starting my PowerShell adventure so my suggestion is basing on my VBS knowledge. I think that there might be a problem with $applications array and its usage in -eq operator. Usually comparison is done between two items so based on VBS syntax I would try with additional foreach to enumerate $applications list:

    $applications = get-content "c:\applications.txt"
    foreach ($App in $applications){
    foreach-object {Get-ChildItem "\\sdlcorpwwps01\WiseSharePoint\Projects" -Recurse | Where-Object {($_.PSIsContainer) -AND $_.NAME -eq $App} | Move-Item -Destination "\\sdlcorpwwps01\smspkgsource$\Archives\Projects"}
    • This worked for one of the folders but I need all of then in my .txt file to be moved.

      • Are there any errors in the PowerShell console?
        I've tested it with local paths and worked fine for all your folders.
        Maybe the problem is with Move-item cmdlet and network paths:
        My another thought is maybe you didn't wait for the completion of the job - as there are over hundred of entries in TXT file and probably much more directories in your REPO it probably will take awhile to finish.
Please log in to comment


Here is a suggestion:

$baseDir = "E:\test"
$targetDir = "E:\test\target"
$toCopyPath = "E:\test\tocopy.txt"

$toCopy = Get-Content $toCopyPath

$toCopy | ForEach-Object {
  Copy-Item "$baseDir\$_" $targetDir -Recurse -Force

Content of tocopy.txt


The folder hierarchy:


│   │   copy.ps1
│   │   tocopy.txt
│   │
│   ├───foldera
│   ├───folderb
│   ├───folderc
│   └───target
│       ├───folderb
│       └───folderc

The yellow marked folders are created after copy.ps1 has started.

Answered 11/26/2014 by: refLye
White Belt

Please log in to comment
Answer this question or Comment on this question for clarity