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.
B
Posts made by bwinc
-
RE: Need a Powershell script to move these files
-
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!