Skip to main content
deleted 168 characters in body
Source Link
LesFerch
  • 469
  • 3
  • 11

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

This script works if your original copy operation left empty folders with no subfolders. If you have empty folders within empty folders, this script will need revising.

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

This script works if your original copy operation left empty folders with no subfolders. If you have empty folders within empty folders, this script will need revising.

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}
added 168 characters in body
Source Link
LesFerch
  • 469
  • 3
  • 11

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

This script works if your original copy operation left empty folders with no subfolders. If you have empty folders within empty folders, this script will need revising.

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

This script works if your original copy operation left empty folders with no subfolders. If you have empty folders within empty folders, this script will need revising.

deleted 327 characters in body
Source Link
LesFerch
  • 469
  • 3
  • 11

Instead of piping the result to a Select statement, just pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
Echo    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}

Then replace the Echo line with an appropriate XCopy command and you're good to go. It should be obvious that each folder name you want to process is provided by $_.FullName.

@Abraham Zinala The third bullet does not answer the question because that only deals with avoiding overwriting existing files. It doesn't handle the OP's issue of not wanting to put back files that have been deleted by the users since the initial copy was done. There is a communication gap because the OP said "take back" instead of "put back".

Instead of piping the result to a Select statement, just pipe it to a ForEach, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
Echo $_.FullName
}

Then replace the Echo line with an appropriate XCopy command and you're good to go. It should be obvious that each folder name you want to process is provided by $_.FullName.

@Abraham Zinala The third bullet does not answer the question because that only deals with avoiding overwriting existing files. It doesn't handle the OP's issue of not wanting to put back files that have been deleted by the users since the initial copy was done. There is a communication gap because the OP said "take back" instead of "put back".

Instead of piping the result to a Select statement, pipe it to a ForEach, create a source path from the destination path ($_.FullName), and use that result in an XCopy command, like this:

(gci "E:\Departments\Marketing" -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | ForEach {
    $Source = ($_.FullName -Replace 'E:\\Departments\Marketing','\\ServerName\SomeDir')
    XCopy $Source $_.FullName /s
}
added 149 characters in body
Source Link
LesFerch
  • 469
  • 3
  • 11
Loading
Source Link
LesFerch
  • 469
  • 3
  • 11
Loading