Note that there are some explanatory texts on larger screens.

plurals
  1. POMove list of empty folders from one volume to another with PowerShell
    primarykey
    data
    text
    <p>I am using PowerShell 2.0 on a Windows SBS 2008 machine with the latest service packs. I have a two line script that finds all empty folders in a directory:</p> <pre><code>$a = Get-ChildItem E:\File_Server -recurse | Where-Object {$_.PSIsContainer -eq $True} $a | Where-Object {$_.GetFiles().Count -eq 0} | [what now?!] </code></pre> <p>The second line finds all folders that are empty, however I'm stumped on the last pipe. Here's what I've tried so far (keep in mind that the following were tried after the second pipe in the second line above):</p> <p><code>$_.move(F:\path)</code> Yes, I tried that. Yes, I'm a PowerShell noob. Of course, I received the error "Expressions are only allowed as the first element of a pipeline."</p> <p><code>move-item -destination F:\Path</code> I receive the lamest error ever: "Move-Item : Source and destination path must have identical roots. Move will not work across volumes." Seriously? What kind of asinine limitation is that?! Moving on...</p> <p><code>copy-item -destination F:\empty_folders</code> Apparently I can get around the limitation of move-item by using <code>copy-item</code> and then use <code>remove-item</code>. No such luck, however. I started the script with <code>copy-item</code> first. PowerShell didn't throw any errors, but also didn't do <em>any</em> thing else. It just sat there for the better part of an hour. No directories were moved.</p> <p><strong>Summary:</strong> How do I take the list of empty folders that I have and, <em>using PowerShell</em>, move those empty directories elsewhere (across volumes!) deleting the originals after the move? Notice the caveat "using PowerShell" as I've already thought about adding RoboCopy to the mix but would like to keep it within PowerShell.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload