Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

Help with script to move directories

$
0
0

Hello Powershell community,

I am trying to write a script and am needing a little assistance, as I cannot get it to work the way it needs to work.

Here is what I am trying to accomplish:

  • Perform a wildcard search for directories containing the following word "archive".
  • Move said directories to a different server, keeping the same directory hierarchy. This is important as most of the folders will have the same name. And since they are related to a specific job, they have to be kept in the same structure.

This script "mostly" works, but cuts off part of the directory structure.

$source = "Q:\DATA\"
$target = "Q:\TEST\" Get-ChildItem $source -Recurse -Filter *Archive* | Where {$_.psiscontainer} | Move-Item -Destination { Join-Path $target $_.FullName.SubString($PWD.Path.Length)} -WhatIf

Here is what it gives me which of course doesn't work:

What if: Performing operation "Move Directory" on Target "Item: D:\AVMF\jmw8\P\JAX\2013\Style Craft\Monticello\Monticello 20131014\Archive Destination: Z:\tyle Craft\Monticello\Monticello 20131014\Archive".

Thanks for the assistance!
(PS I am looking forward to learning powershell and ordered my copy of "Learn Powershell 3 in a month of Lunches".

Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images