Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:52:22+00:00 2026-05-24T09:52:22+00:00

I am using PowerShell 2.0 on a Windows SBS 2008 machine with the latest

  • 0

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:

$a = Get-ChildItem E:\File_Server -recurse | Where-Object {$_.PSIsContainer -eq $True}
$a | Where-Object {$_.GetFiles().Count -eq 0} | [what now?!]

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):

$_.move(F:\path) 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.”

move-item -destination F:\Path 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…

copy-item -destination F:\empty_folders Apparently I can get around the limitation of move-item by using copy-item and then use remove-item. No such luck, however. I started the script with copy-item first. PowerShell didn’t throw any errors, but also didn’t do any thing else. It just sat there for the better part of an hour. No directories were moved.

Summary:
How do I take the list of empty folders that I have and, using PowerShell, 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:52:22+00:00Added an answer on May 24, 2026 at 9:52 am

    I was pretty frustrated with this as well, but like you said copy-item followed by remove-item will work:

    gci e:\file_server | ?{$_.PSIsContainer -eq $true} | ?{$_.GetFiles().count -eq 0} | 
    %{copy-item -LiteralPath $_.fullname -Destination f:\path; remove-item $_.fullname}
    

    Note this is not just a limitation with Move-Item and Powershell but applicable to .Net System.IO.Directory.Move and to be fair, the documentation says so:

    Move-Item will move files between drives that are supported by the
    same provider, but it will move directories only within the same
    drive.

    http://technet.microsoft.com/en-us/library/dd315310.aspx

    PS: You got the "Expressions are only allowed as the first element of a pipeline." error because the $_.move(F:\path) that you were trying must be inside a foreach-object like so – %{$_.move(F:\path)}

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file that I set using PowerShell that contains the version number
Can PowerShell on Windows by itself or using simple shell script, list files and
I have a file system monitoring PowerShell script using System.IO.FileSystemWatcher events. The script works
I'm using windows powershell to manage git, but am limited in that it can't
I've found a PowerShell script that can change the desktop wallpaper of my Windows
I'm using a thrid party Windows service that handles some automation tasks by running
I'm using PowerShell v1.0 (It is a requirement that I cannot use 2.0) and
I'm writing a GUI tool using PowerShell that is able to do most AD
How do I create an Application Pool on IIS 6.0 using a PowerShell script?
NOTE: I'm using PowerShell 2.0 on Windows Vista. I'm trying to add support for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.