ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Topics
    2. bwinc
    B
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 2
    • Groups 0

    bwinc

    @bwinc

    0
    Reputation
    33
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined
    Last Online

    bwinc Unfollow Follow

    Latest posts made by bwinc

    • RE: Need a Powershell script to move these files

      And to clarify, I don't think any of this solves the OP's actual problem. That would certainly require more from the script. But I just remember banging my head with -contains in the past and wanted to save some poor soul some time.

      posted in IT Discussion
      B
      bwinc
    • RE: Need a Powershell script to move these files

      With all due to respect, I don't think that script would work.

      help about_comparison_operators states -contains "Returns true when reference value contained in a collection". So it wouldn't apply here. I remember this tripping me up in the past. -match is what you're looking for. Specifically I'd use -imatch for a case-insensitive match.

      And if I may, here are couple other things I'd change.

      I'd join these two lines together:

      $folders = Get-ChildItem -Path $baseFolder -Directory |
          Where-Object -Property Name -imatch $matchString
      

      Rather than manually concatenating the destination path, I'd use the Join-Path cmdlet. And since there are more than two parameters I'd use a splat.

      foreach ($folder in $folders) {
          $copyParams = @{
              Path        = $folder.FullName
              Destination = Join-Path -Path $destFolder -ChildPath $folder.Name
              Recurse     = $true
          }
          Copy-item @copyParams
      }
      

      Hope this helps!

      posted in IT Discussion
      B
      bwinc