file - How to find, filter and copy directory and contents to a location dictated by part of find result ) in Powershell -


using powershell preferably, otherwise vbscript. perl or batch. (any way it's not manual job).

i have list of user profiles:

\\fileserver\profiles\user1\findmedirectory\dir1 \\fileserver\profiles\user2\findmedirectory\dir1 \\fileserver\profiles\user3\notfindme\dir1 

i wish copy instances of "findmedirectory" recursively down to

\\fileserver\newprofilesdirectory\user1\ \\fileserver\newprofilesdirectory\user2\ \\fileserver\newprofilesdirectory\user3\ 

by finding example first entry:

\\fileserver\profiles\user1\appdata\findmedirectory\dir1 `$dest = \\fileserver\newprofiledirectory $user = user1 (from result above) $copydir = findmedirectory  $complete_dest = $dest & $user & $copydir (i.e.  \\fileserver\newprofiledirectory\user1\findmedirectory ) ` 

there other files in both locations underneath user1, user2 , user3.

so far have: get-childitem "\\fileserver\profiles" -filter "findmedirectory" -force -recurse | where-object {$_.psiscontainer} | select-object fullname

this works ^^.

when try pipe grab string of "username" i.e. user1. starts fall apart:

$files = get-childitem "\\fileserver\profiles" -filter "*findmedirectory*" -force -recurse | where-object {$_.psiscontainer} | select-object fullname
foreach ($file in $files) { get-item $files.fullname).parent.name }

please help.

this should work:

$specialdirectory = "xyz" $destination = "zyx"  $1 = "\\fileserver\profiles\" | get-childitem $user = $1.name | {$_ -match "user"} $user | foreach { $check = test-path -pathtype "\\fileserver\profiles\$_\appdata\$specialdirectory" if ($check -eq $true) {copy-item \\fileserver\profiles\$_\appdata\$specialdirectory -destination c:\$destination -recurse}         } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -